#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *, int);
int util_cpu_time();
int time_usage(char *name) {
  static int time_init;
  int time_current;
  static int flag = 1;
  if (flag) {
    time_init = util_cpu_time();
    flag = 0;
    return time_init;
  }
  time_current = util_cpu_time();
  printf("%s\t %ld\n", name, (time_current - time_init) / 1000L);
  return time_current;
}


x86 assembly (clang, -O0):
<time_usage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpl   $0x0,0x2efd(%rip)
je     115e <time_usage+0x3e>
mov    $0x0,%al
call   1040 <util_cpu_time@plt>
mov    %eax,0x2ef2(%rip)
movl   $0x0,0x2ee0(%rip)
mov    0x2ee2(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    1195 <time_usage+0x75>
mov    $0x0,%al
call   1040 <util_cpu_time@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
sub    0x2ec3(%rip),%eax
cltq
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %eax,%edx
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_usage>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2f0b(%rip),%bl
xor    %eax,%eax
call   1040 <util_cpu_time@plt>
mov    %eax,%ebp
test   %bl,%bl
je     1169 <time_usage+0x49>
mov    %ebp,%eax
sub    0x2ef2(%rip),%eax
cltq
imul   $0x10624dd3,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x26,%rdx
add    %eax,%edx
lea    0xea1(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
jmp    1176 <time_usage+0x56>
mov    %ebp,0x2ec5(%rip)
movb   $0x1,0x2ec2(%rip)
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@time_usage.time_init = internal global i32 0
@time_usage.flag = internal global i32 1
@.str = [9 x i8] c"%s\09 %ld\0A\00"
define i32 @time_usage(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i32, i32* @time_usage.flag
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 (...) @util_cpu_time()
store i32 %8, i32* @time_usage.time_init
store i32 0, i32* @time_usage.flag
%9 = load i32, i32* @time_usage.time_init
store i32 %9, i32* %2
br label %21
10: ; preds = %1
%11 = call i32 (...) @util_cpu_time()
store i32 %11, i32* %4
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = load i32, i32* @time_usage.time_init
%15 = sub nsw i32 %13, %14
%16 = sext i32 %15 to i64
%17 = sdiv i64 %16, 1000
%18 = trunc i64 %17 to i32
%19 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %18)
%20 = load i32, i32* %4
store i32 %20, i32* %2
br label %21
21: ; preds = %10, %7
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@time_usage.time_init = internal unnamed_addr global i32 0
@time_usage.flag = internal unnamed_addr global i1 false
@.str = [9 x i8] c"%s\09 %ld\0A\00"
define i32 @time_usage(i8* %0) {
%2 = load i1, i1* @time_usage.flag
%3 = tail call i32 (...) @util_cpu_time()
br i1 %2, label %5, label %4
4: ; preds = %1
store i32 %3, i32* @time_usage.time_init
store i1 true, i1* @time_usage.flag
br label %10
5: ; preds = %1
%6 = load i32, i32* @time_usage.time_init
%7 = sub nsw i32 %3, %6
%8 = sdiv i32 %7, 1000
%9 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %8)
br label %10
10: ; preds = %5, %4
ret i32 %3
}