#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int tv_sec;
  int tv_usec;
};
struct TYPE_3__ {
  int tv_sec;
  int tv_usec;
};
struct rusage {
  TYPE_2__ ru_stime;
  TYPE_1__ ru_utime;
};
typedef int clock_t;

/* Variables and functions */
int CLOCKS_PER_SEC;
int /*<<< orphan*/ RUSAGE_SELF;
scalar_t__ getrusage(int /*<<< orphan*/, struct rusage *);
clock_t clock(void) {
  struct rusage ru;
  clock_t hz = CLOCKS_PER_SEC;
  if (getrusage(RUSAGE_SELF, &ru))
    return ((clock_t)-1);
  return (clock_t)((ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) * hz +
                   (ru.ru_utime.tv_usec + ru.ru_stime.tv_usec + 50) / 100 * hz /
                       10000);
}


x86 assembly (clang, -O0):
<clock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ec9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <getrusage@plt>
cmp    $0x0,%rax
je     114c <clock+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1180 <clock+0x70>
mov    -0x10(%rbp),%eax
add    -0x18(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    -0x14(%rbp),%eax
add    $0x32,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
imul   -0x1c(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clock>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ecc(%rip),%rax
mov    (%rax),%ebx
mov    0x2eb3(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <getrusage@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1184 <clock+0x74>
mov    (%rsp),%ecx
add    0x8(%rsp),%ecx
mov    0x4(%rsp),%eax
imul   %ebx,%ecx
mov    0xc(%rsp),%edx
add    %edx,%eax
add    $0x32,%eax
cltq
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rax
add    %edx,%eax
imul   %ebx,%eax
cltq
imul   $0x68db8bad,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rax
add    %edx,%eax
add    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_3__ = type { i32, i32 }
@CLOCKS_PER_SEC = global i32 0
@RUSAGE_SELF = global i32 0
define i32 @clock() {
%1 = alloca i32
%2 = alloca %struct.rusage
%3 = alloca i32
%4 = load i32, i32* @CLOCKS_PER_SEC
store i32 %4, i32* %3
%5 = load i32, i32* @RUSAGE_SELF
%6 = call i64 @getrusage(i32 %5, %struct.rusage* %2)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 -1, i32* %1
br label %32
9: ; preds = %0
%10 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 1
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 0
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = add nsw i32 %12, %15
%17 = load i32, i32* %3
%18 = mul nsw i32 %16, %17
%19 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = add nsw i32 %21, %24
%26 = add nsw i32 %25, 50
%27 = sdiv i32 %26, 100
%28 = load i32, i32* %3
%29 = mul nsw i32 %27, %28
%30 = sdiv i32 %29, 10000
%31 = add nsw i32 %18, %30
store i32 %31, i32* %1
br label %32
32: ; preds = %9, %8
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_3__ = type { i32, i32 }
@CLOCKS_PER_SEC = global i32 0
@RUSAGE_SELF = global i32 0
define i32 @clock() {
%1 = alloca %struct.rusage
%2 = bitcast %struct.rusage* %1 to i8*
%3 = load i32, i32* @CLOCKS_PER_SEC
%4 = load i32, i32* @RUSAGE_SELF
%5 = call i64 @getrusage(i32 %4, %struct.rusage* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %24
7: ; preds = %0
%8 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 1, i32 0
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0, i32 0
%11 = load i32, i32* %10
%12 = add nsw i32 %11, %9
%13 = mul nsw i32 %12, %3
%14 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 1, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0, i32 1
%17 = load i32, i32* %16
%18 = add i32 %15, 50
%19 = add i32 %18, %17
%20 = sdiv i32 %19, 100
%21 = mul nsw i32 %20, %3
%22 = sdiv i32 %21, 10000
%23 = add nsw i32 %22, %13
br label %24
24: ; preds = %0, %7
%25 = phi i32 [ %23, %7 ], [ -1, %0 ]
ret i32 %25
}