#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct tms {
  unsigned long tms_stime;
  scalar_t__ tms_utime;
};
typedef unsigned long clock_t;

/* Variables and functions */
long CLOCKS_PER_SEC;
int /*<<< orphan*/ _SC_CLK_TCK;
long __sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ __times(struct tms *);
clock_t clock(void) {
  struct tms buf;
  long clk_tck = __sysconf(_SC_CLK_TCK);
  __times(&buf);
  return (clk_tck <= CLOCKS_PER_SEC)
             ? ((unsigned long)buf.tms_utime + buf.tms_stime) *
                   (CLOCKS_PER_SEC / clk_tck)
             : ((unsigned long)buf.tms_utime + buf.tms_stime) /
                   (clk_tck / CLOCKS_PER_SEC);
}


x86 assembly (clang, -O0):
<clock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
call   1030 <__sysconf@plt>
mov    %rax,-0x18(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <__times@plt>
mov    -0x18(%rbp),%rax
mov    0x2e9a(%rip),%rcx
cmp    (%rcx),%rax
jg     1187 <clock+0x67>
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%rax
cqto
idivq  -0x18(%rbp)
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
imul   %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    11b3 <clock+0x93>
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e4a(%rip),%rcx
cqto
idivq  (%rcx)
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clock>:
push   %rbx
sub    $0x10,%rsp
mov    0x2eac(%rip),%rax
mov    (%rax),%edi
call   1030 <__sysconf@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
call   1040 <__times@plt>
mov    0x2ea3(%rip),%rax
mov    (%rax),%rsi
mov    (%rsp),%rcx
add    0x8(%rsp),%rcx
mov    %rbx,%rax
or     %rsi,%rax
cmp    %rsi,%rbx
jle    116f <clock+0x4f>
shr    $0x20,%rax
je     1183 <clock+0x63>
mov    %rbx,%rax
cqto
idiv   %rsi
mov    %rax,%rsi
jmp    118b <clock+0x6b>
shr    $0x20,%rax
je     11a4 <clock+0x84>
mov    %rsi,%rax
cqto
idiv   %rbx
imul   %rax,%rcx
jmp    11b8 <clock+0x98>
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
mov    %eax,%esi
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     11b0 <clock+0x90>
mov    %rcx,%rax
xor    %edx,%edx
div    %rsi
mov    %rax,%rcx
jmp    11b8 <clock+0x98>
mov    %esi,%eax
xor    %edx,%edx
div    %ebx
imul   %rax,%rcx
jmp    11b8 <clock+0x98>
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
mov    %eax,%ecx
mov    %rcx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tms = type { i64, i64 }
@_SC_CLK_TCK = global i32 0
@CLOCKS_PER_SEC = global i64 0
define i64 @clock() {
%1 = alloca %struct.tms
%2 = alloca i64
%3 = load i32, i32* @_SC_CLK_TCK
%4 = call i64 @__sysconf(i32 %3)
store i64 %4, i64* %2
%5 = call i32 @__times(%struct.tms* %1)
%6 = load i64, i64* %2
%7 = load i64, i64* @CLOCKS_PER_SEC
%8 = icmp sle i64 %6, %7
br i1 %8, label %9, label %19
9: ; preds = %0
%10 = getelementptr inbounds %struct.tms, %struct.tms* %1, i32 0, i32 1
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.tms, %struct.tms* %1, i32 0, i32 0
%13 = load i64, i64* %12
%14 = add i64 %11, %13
%15 = load i64, i64* @CLOCKS_PER_SEC
%16 = load i64, i64* %2
%17 = sdiv i64 %15, %16
%18 = mul i64 %14, %17
br label %29
19: ; preds = %0
%20 = getelementptr inbounds %struct.tms, %struct.tms* %1, i32 0, i32 1
%21 = load i64, i64* %20
%22 = getelementptr inbounds %struct.tms, %struct.tms* %1, i32 0, i32 0
%23 = load i64, i64* %22
%24 = add i64 %21, %23
%25 = load i64, i64* %2
%26 = load i64, i64* @CLOCKS_PER_SEC
%27 = sdiv i64 %25, %26
%28 = udiv i64 %24, %27
br label %29
29: ; preds = %19, %9
%30 = phi i64 [ %18, %9 ], [ %28, %19 ]
ret i64 %30
}

LLVM IR (-O2):
%struct.tms = type { i64, i64 }
@_SC_CLK_TCK = global i32 0
@CLOCKS_PER_SEC = global i64 0
define i64 @clock() {
%1 = alloca %struct.tms
%2 = bitcast %struct.tms* %1 to i8*
%3 = load i32, i32* @_SC_CLK_TCK
%4 = tail call i64 @__sysconf(i32 %3)
%5 = call i32 @__times(%struct.tms* %1)
%6 = load i64, i64* @CLOCKS_PER_SEC
%7 = icmp sgt i64 %4, %6
%8 = getelementptr inbounds %struct.tms, %struct.tms* %1, i64 0, i32 1
%9 = load i64, i64* %8
%10 = getelementptr inbounds %struct.tms, %struct.tms* %1, i64 0, i32 0
%11 = load i64, i64* %10
%12 = add i64 %11, %9
br i1 %7, label %16, label %13
13: ; preds = %0
%14 = sdiv i64 %6, %4
%15 = mul i64 %12, %14
br label %19
16: ; preds = %0
%17 = sdiv i64 %4, %6
%18 = udiv i64 %12, %17
br label %19
19: ; preds = %16, %13
%20 = phi i64 [ %15, %13 ], [ %18, %16 ]
ret i64 %20
}