#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 */
typedef int /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};

/* Variables and functions */
char *asctime(struct tm *);
unsigned long ioUTCMicrosecondsNow();
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ time(int /*<<< orphan*/);
void printPhaseTime(int phase) {
  static int printTimes;
  static unsigned long lastusecs;
  unsigned long nowusecs, usecs;
  if (phase == 1) {
    time_t nowt;
    struct tm nowtm;
    printTimes = 1;
    nowt = time(0);
    nowtm = *localtime(&nowt);
    printf("started at %s", asctime(&nowtm));
    lastusecs = ioUTCMicrosecondsNow();
    return;
  }
  if (!printTimes)
    return;
  nowusecs = ioUTCMicrosecondsNow();
  usecs = nowusecs - lastusecs;
  lastusecs = nowusecs;
  if (phase == 2)
    printf("loaded in %lu.%03lus\n", (unsigned long)(usecs / 1000000ULL),
           (unsigned long)((usecs % 1000000ULL + 1000ULL / 2) / 1000ULL));
  if (phase == 3) {
    printTimes = 0;
    if (usecs >= 1ULL << 32)
      printf("ran for a long time\n");
    else
      printf("ran for %lu.%03lus\n", (unsigned long)(usecs / 1000000ULL),
             (unsigned long)((usecs % 1000000ULL + 1000ULL / 2) / 1000ULL));
  }
}


x86 assembly (clang, -O0):
<printPhaseTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    11b4 <printPhaseTime+0x64>
movl   $0x1,0x2ee1(%rip)
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <asctime@plt>
mov    %rax,%rsi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <ioUTCMicrosecondsNow@plt>
mov    %rax,0x2ea9(%rip)
jmp    12bb <printPhaseTime+0x16b>
cmpl   $0x0,0x2e95(%rip)
jne    11c6 <printPhaseTime+0x76>
jmp    12bb <printPhaseTime+0x16b>
mov    $0x0,%al
call   1070 <ioUTCMicrosecondsNow@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    0x2e7c(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,0x2e6d(%rip)
cmpl   $0x2,-0x4(%rbp)
jne    1238 <printPhaseTime+0xe8>
mov    -0x18(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rsi
mov    -0x18(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,%rax
add    $0x1f4,%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x3,-0x4(%rbp)
jne    12bb <printPhaseTime+0x16b>
movl   $0x0,0x2e04(%rip)
movabs $0x100000000,%rax
cmp    %rax,-0x18(%rbp)
jb     1273 <printPhaseTime+0x123>
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12b6 <printPhaseTime+0x166>
mov    -0x18(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rsi
mov    -0x18(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,%rax
add    $0x1f4,%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12bb <printPhaseTime+0x16b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printPhaseTime>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jne    11b7 <printPhaseTime+0x57>
movb   $0x1,0x2ee7(%rip)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1050 <asctime@plt>
lea    0xe63(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1080 <ioUTCMicrosecondsNow@plt>
mov    %rax,0x2eab(%rip)
jmp    1220 <printPhaseTime+0xc0>
cmpb   $0x1,0x2e9a(%rip)
jne    1220 <printPhaseTime+0xc0>
mov    %edi,%ebx
xor    %eax,%eax
call   1080 <ioUTCMicrosecondsNow@plt>
mov    %rax,%rcx
sub    0x2e8d(%rip),%rcx
mov    %rax,0x2e86(%rip)
cmp    $0x3,%ebx
je     1226 <printPhaseTime+0xc6>
cmp    $0x2,%ebx
jne    1220 <printPhaseTime+0xc0>
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mov    %rcx,%rax
mul    %rdx
shr    $0x12,%rdx
imul   $0xf4240,%edx,%eax
sub    %eax,%ecx
add    $0x1f4,%ecx
imul   $0x10624dd3,%rcx,%rax
shr    $0x26,%rax
lea    0xdf6(%rip),%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
jmp    1274 <printPhaseTime+0x114>
add    $0x10,%rsp
pop    %rbx
ret
movb   $0x0,0x2e2b(%rip)
mov    %rcx,%rax
shr    $0x20,%rax
je     1247 <printPhaseTime+0xe7>
lea    0xdfb(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1040 <puts@plt>
mov    %ecx,%eax
imul   $0x431bde83,%rax,%rsi
shr    $0x32,%rsi
imul   $0xf4240,%esi,%eax
sub    %eax,%ecx
add    $0x1f4,%ecx
imul   $0x10624dd3,%rcx,%rdx
shr    $0x26,%rdx
lea    0xdb0(%rip),%rdi
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
jmp    1060 <printf@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@printPhaseTime.printTimes = internal global i32 0
@printPhaseTime.lastusecs = internal global i64 0
@.str = [14 x i8] c"started at %s\00"
@.str.1 = [22 x i8] c"loaded in %lu.%03lus\0A\00"
@.str.2 = [21 x i8] c"ran for a long time\0A\00"
@.str.3 = [20 x i8] c"ran for %lu.%03lus\0A\00"
define void @printPhaseTime(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca %struct.tm
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %17
9: ; preds = %1
store i32 1, i32* @printPhaseTime.printTimes
%10 = call i32 @time(i32 0)
store i32 %10, i32* %5
%11 = call %struct.tm* @localtime(i32* %5)
%12 = bitcast %struct.tm* %6 to i8*
%13 = bitcast %struct.tm* %11 to i8*
%14 = call i8* @asctime(%struct.tm* %6)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i64 (...) @ioUTCMicrosecondsNow()
store i64 %16, i64* @printPhaseTime.lastusecs
br label %54
17: ; preds = %1
%18 = load i32, i32* @printPhaseTime.printTimes
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %17
br label %54
21: ; preds = %17
%22 = call i64 (...) @ioUTCMicrosecondsNow()
store i64 %22, i64* %3
%23 = load i64, i64* %3
%24 = load i64, i64* @printPhaseTime.lastusecs
%25 = sub i64 %23, %24
store i64 %25, i64* %4
%26 = load i64, i64* %3
store i64 %26, i64* @printPhaseTime.lastusecs
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 2
br i1 %28, label %29, label %37
29: ; preds = %21
%30 = load i64, i64* %4
%31 = udiv i64 %30, 1000000
%32 = load i64, i64* %4
%33 = urem i64 %32, 1000000
%34 = add i64 %33, 500
%35 = udiv i64 %34, 1000
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %31, i64 %35)
br label %37
37: ; preds = %29, %21
%38 = load i32, i32* %2
%39 = icmp eq i32 %38, 3
br i1 %39, label %40, label %54
40: ; preds = %37
store i32 0, i32* @printPhaseTime.printTimes
%41 = load i64, i64* %4
%42 = icmp uge i64 %41, 4294967296
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %53
45: ; preds = %40
%46 = load i64, i64* %4
%47 = udiv i64 %46, 1000000
%48 = load i64, i64* %4
%49 = urem i64 %48, 1000000
%50 = add i64 %49, 500
%51 = udiv i64 %50, 1000
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i64 %47, i64 %51)
br label %53
53: ; preds = %45, %43
br label %54
54: ; preds = %9, %20, %53, %37
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@printPhaseTime.printTimes = internal unnamed_addr global i1 false
@printPhaseTime.lastusecs = internal unnamed_addr global i64 0
@.str = [14 x i8] c"started at %s\00"
@.str.1 = [22 x i8] c"loaded in %lu.%03lus\0A\00"
@.str.3 = [20 x i8] c"ran for %lu.%03lus\0A\00"
@str = [20 x i8] c"ran for a long time\00"
define void @printPhaseTime(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.tm
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %16
5: ; preds = %1
%6 = bitcast i32* %2 to i8*
%7 = bitcast %struct.tm* %3 to i8*
store i1 true, i1* @printPhaseTime.printTimes
%8 = tail call i32 @time(i32 0)
store i32 %8, i32* %2
%9 = call %struct.tm* @localtime(i32* %2)
%10 = getelementptr %struct.tm, %struct.tm* %9, i64 0, i32 0
%11 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%12 = load i32, i32* %10
store i32 %12, i32* %11
%13 = call i8* @asctime(%struct.tm* %3)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i64 (...) @ioUTCMicrosecondsNow()
store i64 %15, i64* @printPhaseTime.lastusecs
br label %43
16: ; preds = %1
%17 = load i1, i1* @printPhaseTime.printTimes
br i1 %17, label %18, label %43
18: ; preds = %16
%19 = tail call i64 (...) @ioUTCMicrosecondsNow()
%20 = load i64, i64* @printPhaseTime.lastusecs
%21 = sub i64 %19, %20
store i64 %19, i64* @printPhaseTime.lastusecs
switch i32 %0, label %43 [
i32 2, label %22
i32 3, label %30
]
22: ; preds = %18
%23 = udiv i64 %21, 1000000
%24 = urem i64 %21, 1000000
%25 = trunc i64 %24 to i32
%26 = add nuw nsw i32 %25, 500
%27 = udiv i32 %26, 1000
%28 = zext i32 %27 to i64
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %23, i64 %28)
br label %43
30: ; preds = %18
store i1 false, i1* @printPhaseTime.printTimes
%31 = icmp ugt i64 %21, 4294967295
br i1 %31, label %32, label %34
32: ; preds = %30
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %43
34: ; preds = %30
%35 = trunc i64 %21 to i32
%36 = udiv i32 %35, 1000000
%37 = zext i32 %36 to i64
%38 = urem i32 %35, 1000000
%39 = add nuw nsw i32 %38, 500
%40 = udiv i32 %39, 1000
%41 = zext i32 %40 to i64
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i64 %37, i64 %41)
br label %43
43: ; preds = %22, %34, %32, %18, %16, %5
ret void
}