#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 scalar_t__ time_t;
struct tms {
  int /*<<< orphan*/ tms_stime;
  int /*<<< orphan*/ tms_utime;
};
struct timeval {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
struct timespec {
  scalar_t__ tv_nsec;
  scalar_t__ tv_sec;
};
typedef int clockid_t;
typedef int clock_t;

/* Variables and functions */
int CLOCK_MONOTONIC;
int CLOCK_MONOTONIC_COARSE;
int CLOCK_MONOTONIC_RAW;
int CLOCK_PROCESS_CPUTIME_ID;
int CLOCK_REALTIME;
int CLOCK_THREAD_CPUTIME_ID;
int /*<<< orphan*/ _SC_CLK_TCK;
int clock_getres(int, struct timespec *);
int clock_gettime(int, struct timespec *);
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sysconf(int /*<<< orphan*/);
scalar_t__ time(int /*<<< orphan*/ *);
int times(struct tms *);
int time2_test(void) {
  struct timeval tv0;
  struct timespec tp0;
  struct tms tms0;
  time_t te0;
  int ret;
  int i;
  struct timespec timeres[10];
  struct timespec timeres2[10];
  clockid_t clocks[] = {
      CLOCK_REALTIME,         CLOCK_MONOTONIC,          CLOCK_MONOTONIC_RAW,
      CLOCK_MONOTONIC_COARSE, CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID,
      (clockid_t)-1};
  te0 = time(NULL);
  ret = gettimeofday(&tv0, NULL);
  if (ret) {
    perror("gettimeofday fail ");
  }
  ret = clock_gettime(CLOCK_REALTIME, &tp0);
  if ((clock_t)ret == -1)
    perror("clock gettime fail ");
  printf("clk per sec %ld\n", sysconf(_SC_CLK_TCK));
  ret = times(&tms0);
  if (ret < 0)
    perror("times fail ");
  printf("current time %d\n", (int)te0);
  printf("tv sec %ld usec %ld\n", tv0.tv_sec, tv0.tv_usec);
  printf("tp sec %ld nsec %ld\n", tp0.tv_sec, tp0.tv_nsec);
  printf("tms sec %ld usec %ld\n", tms0.tms_utime, tms0.tms_stime);
  for (i = 0; clocks[i] != (clockid_t)-1; i++) {
    struct timespec res;
    int ret;
    ret = clock_getres(clocks[i], &res);
    if (ret)
      perror("clock_getres");
    else
      printf("%d clock=%d sec=%ld nsec=%ld\n", i, clocks[i], res.tv_sec,
             res.tv_nsec);
  }
  for (i = 0; clocks[i] != (clockid_t)-1; i++) {
    ret = clock_gettime(clocks[i], &timeres[i]);
    if ((clock_t)ret == -1) {
      perror("gettime fail");
      printf("%d %d\n", i, ret);
    }
  }
  sleep(5);
  for (i = 0; clocks[i] != (clockid_t)-1; i++) {
    ret = clock_gettime(clocks[i], &timeres2[i]);
    if ((clock_t)ret == -1) {
      perror("gettime fail");
      printf("%d %d\n", i, ret);
    }
  }
  for (i = 0; clocks[i] != (clockid_t)-1; i++) {
    printf("%d | %d | %ld %ld \n", i, clocks[i],
           timeres2[i].tv_sec - timeres[i].tv_sec,
           timeres2[i].tv_nsec - timeres[i].tv_nsec);
  }
  return 0;
}


x86 assembly (clang, -O0):
<time2_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x190(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18c(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x188(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x184(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x180(%rbp)
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x17c(%rbp)
movl   $0xffffffff,-0x178(%rbp)
ff ff ff
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x28(%rbp)
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1232 <time2_test+0xa2>
lea    0xdd3(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    125d <time2_test+0xcd>
lea    0xdbb(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   10a0 <sysconf@plt>
mov    %eax,%esi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1080 <times@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    129d <time2_test+0x10d>
lea    0xda0(%rip),%rdi
call   1090 <perror@plt>
mov    -0x28(%rbp),%rax
mov    %eax,%esi
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmpl   $0xffffffff,-0x190(%rbp,%rax,4)
ff
je     1382 <time2_test+0x1f2>
movslq -0x30(%rbp),%rax
mov    -0x190(%rbp,%rax,4),%edi
lea    -0x1a0(%rbp),%rsi
call   1070 <clock_getres@plt>
mov    %eax,-0x1a4(%rbp)
cmpl   $0x0,-0x1a4(%rbp)
je     1345 <time2_test+0x1b5>
lea    0xd5a(%rip),%rdi
call   1090 <perror@plt>
jmp    136f <time2_test+0x1df>
mov    -0x30(%rbp),%esi
movslq -0x30(%rbp),%rax
mov    -0x190(%rbp,%rax,4),%edx
mov    -0x198(%rbp),%rcx
mov    -0x1a0(%rbp),%r8
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1374 <time2_test+0x1e4>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12f8 <time2_test+0x168>
movl   $0x0,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmpl   $0xffffffff,-0x190(%rbp,%rax,4)
ff
je     13fd <time2_test+0x26d>
movslq -0x30(%rbp),%rax
mov    -0x190(%rbp,%rax,4),%edi
movslq -0x30(%rbp),%rax
lea    -0xd0(%rbp),%rsi
shl    $0x4,%rax
add    %rax,%rsi
call   1030 <clock_gettime@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    13ea <time2_test+0x25a>
lea    0xcef(%rip),%rdi
call   1090 <perror@plt>
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xcea(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13ef <time2_test+0x25f>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1389 <time2_test+0x1f9>
mov    $0x5,%edi
call   10b0 <sleep@plt>
movl   $0x0,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmpl   $0xffffffff,-0x190(%rbp,%rax,4)
ff
je     1482 <time2_test+0x2f2>
movslq -0x30(%rbp),%rax
mov    -0x190(%rbp,%rax,4),%edi
movslq -0x30(%rbp),%rax
lea    -0x170(%rbp),%rsi
shl    $0x4,%rax
add    %rax,%rsi
call   1030 <clock_gettime@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    146f <time2_test+0x2df>
lea    0xc6a(%rip),%rdi
call   1090 <perror@plt>
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xc65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1474 <time2_test+0x2e4>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    140e <time2_test+0x27e>
movl   $0x0,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmpl   $0xffffffff,-0x190(%rbp,%rax,4)
ff
je     151b <time2_test+0x38b>
mov    -0x30(%rbp),%esi
movslq -0x30(%rbp),%rax
mov    -0x190(%rbp,%rax,4),%edx
movslq -0x30(%rbp),%rcx
lea    -0x170(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rcx
movslq -0x30(%rbp),%rdi
lea    -0xd0(%rbp),%rax
shl    $0x4,%rdi
add    %rdi,%rax
sub    0x8(%rax),%rcx
movslq -0x30(%rbp),%rdi
lea    -0x170(%rbp),%rax
shl    $0x4,%rdi
add    %rdi,%rax
mov    (%rax),%r8
movslq -0x30(%rbp),%rdi
lea    -0xd0(%rbp),%rax
shl    $0x4,%rdi
add    %rdi,%rax
sub    (%rax),%r8
lea    0xbce(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1489 <time2_test+0x2f9>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time2_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x188,%rsp
mov    0x2e08(%rip),%rbp
mov    0x0(%rbp),%r14d
mov    %r14d,(%rsp)
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
movl   $0xffffffff,0x18(%rsp)
ff
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,%rbx
lea    0x28(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
test   %eax,%eax
jne    1471 <time2_test+0x2e1>
mov    0x0(%rbp),%edi
lea    0x30(%rsp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
je     1482 <time2_test+0x2f2>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   10a0 <sysconf@plt>
lea    0xde5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x20(%rsp),%rdi
call   1080 <times@plt>
test   %eax,%eax
js     1493 <time2_test+0x303>
lea    0xde0(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x28(%rsp),%edx
mov    0x2c(%rsp),%esi
lea    0xdd9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x38(%rsp),%esi
mov    0x30(%rsp),%rdx
lea    0xdd7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rsp),%edx
mov    0x24(%rsp),%esi
lea    0xdd6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0xffffffff,%r14d
je     1379 <time2_test+0x1e9>
lea    0x40(%rsp),%r13
lea    0xddc(%rip),%r12
lea    0xdc8(%rip),%r15
xor    %ebp,%ebp
mov    %r14d,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r13,%rsi
call   1070 <clock_getres@plt>
test   %eax,%eax
jne    1315 <time2_test+0x185>
mov    0x40(%rsp),%r8
mov    0x48(%rsp),%rcx
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp,%rbp,4),%ebx
add    $0x1,%rbp
cmp    $0xffffffff,%ebx
jne    12e0 <time2_test+0x150>
jmp    131f <time2_test+0x18f>
mov    %r15,%rdi
call   1090 <perror@plt>
jmp    1306 <time2_test+0x176>
cmp    $0xffffffff,%r14d
je     1379 <time2_test+0x1e9>
lea    0xd94(%rip),%r15
lea    0xd9a(%rip),%r12
xor    %ebp,%ebp
mov    %r14d,%edi
jmp    1351 <time2_test+0x1c1>
nopw   0x0(%rax,%rax,1)
mov    0x4(%rsp,%rbp,4),%edi
add    $0x1,%rbp
add    $0x10,%r13
cmp    $0xffffffff,%edi
je     1397 <time2_test+0x207>
mov    %r13,%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    1340 <time2_test+0x1b0>
mov    %r15,%rdi
call   1090 <perror@plt>
mov    %r12,%rdi
mov    %ebp,%esi
mov    $0xffffffff,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1340 <time2_test+0x1b0>
mov    $0x5,%edi
call   10b0 <sleep@plt>
xor    %eax,%eax
add    $0x188,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x5,%edi
call   10b0 <sleep@plt>
cmp    $0xffffffff,%r14d
je     1383 <time2_test+0x1f3>
lea    0xe0(%rsp),%rbx
lea    0xd0a(%rip),%r15
lea    0xd10(%rip),%r12
xor    %ebp,%ebp
mov    %r14d,%edi
jmp    13e1 <time2_test+0x251>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x4(%rsp,%rbp,4),%edi
add    $0x1,%rbp
add    $0x10,%rbx
cmp    $0xffffffff,%edi
je     1409 <time2_test+0x279>
mov    %rbx,%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    13d0 <time2_test+0x240>
mov    %r15,%rdi
call   1090 <perror@plt>
mov    %r12,%rdi
mov    %ebp,%esi
mov    $0xffffffff,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    13d0 <time2_test+0x240>
cmp    $0xffffffff,%r14d
je     1383 <time2_test+0x1f3>
mov    $0x8,%ebx
lea    0xcb5(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0xd8(%rsp,%rbx,1),%r8
mov    0xe0(%rsp,%rbx,1),%rcx
sub    0x40(%rsp,%rbx,1),%rcx
sub    0x38(%rsp,%rbx,1),%r8
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp,%rbp,4),%r14d
add    $0x1,%rbp
add    $0x10,%rbx
cmp    $0xffffffff,%r14d
jne    1430 <time2_test+0x2a0>
jmp    1383 <time2_test+0x1f3>
lea    0xb88(%rip),%rdi
call   1090 <perror@plt>
jmp    1217 <time2_test+0x87>
lea    0xb8a(%rip),%rdi
call   1090 <perror@plt>
jmp    122d <time2_test+0x9d>
lea    0xb9e(%rip),%rdi
call   1090 <perror@plt>
jmp    125d <time2_test+0xcd>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.timespec = type { i64, i64 }
%struct.tms = type { i32, i32 }
@CLOCK_REALTIME = global i32 0
@CLOCK_MONOTONIC = global i32 0
@CLOCK_MONOTONIC_RAW = global i32 0
@CLOCK_MONOTONIC_COARSE = global i32 0
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
@CLOCK_THREAD_CPUTIME_ID = global i32 0
@.str = [19 x i8] c"gettimeofday fail \00"
@.str.1 = [20 x i8] c"clock gettime fail \00"
@.str.2 = [17 x i8] c"clk per sec %ld\0A\00"
@_SC_CLK_TCK = global i32 0
@.str.3 = [12 x i8] c"times fail \00"
@.str.4 = [17 x i8] c"current time %d\0A\00"
@.str.5 = [21 x i8] c"tv sec %ld usec %ld\0A\00"
@.str.6 = [21 x i8] c"tp sec %ld nsec %ld\0A\00"
@.str.7 = [22 x i8] c"tms sec %ld usec %ld\0A\00"
@.str.8 = [13 x i8] c"clock_getres\00"
@.str.9 = [30 x i8] c"%d clock=%d sec=%ld nsec=%ld\0A\00"
@.str.10 = [13 x i8] c"gettime fail\00"
@.str.11 = [7 x i8] c"%d %d\0A\00"
@.str.12 = [20 x i8] c"%d | %d | %ld %ld \0A\00"
define i32 @time2_test() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timespec
%3 = alloca %struct.tms
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca [10 x %struct.timespec]
%8 = alloca [10 x %struct.timespec]
%9 = alloca [7 x i32]
%10 = alloca %struct.timespec
%11 = alloca i32
%12 = getelementptr inbounds [7 x i32], [7 x i32]* %9, i64 0, i64 0
%13 = load i32, i32* @CLOCK_REALTIME
store i32 %13, i32* %12
%14 = getelementptr inbounds i32, i32* %12, i64 1
%15 = load i32, i32* @CLOCK_MONOTONIC
store i32 %15, i32* %14
%16 = getelementptr inbounds i32, i32* %14, i64 1
%17 = load i32, i32* @CLOCK_MONOTONIC_RAW
store i32 %17, i32* %16
%18 = getelementptr inbounds i32, i32* %16, i64 1
%19 = load i32, i32* @CLOCK_MONOTONIC_COARSE
store i32 %19, i32* %18
%20 = getelementptr inbounds i32, i32* %18, i64 1
%21 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
store i32 %21, i32* %20
%22 = getelementptr inbounds i32, i32* %20, i64 1
%23 = load i32, i32* @CLOCK_THREAD_CPUTIME_ID
store i32 %23, i32* %22
%24 = getelementptr inbounds i32, i32* %22, i64 1
store i32 -1, i32* %24
%25 = call i64 @time(i32* null)
store i64 %25, i64* %4
%26 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %0
%30 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29, %0
%32 = load i32, i32* @CLOCK_REALTIME
%33 = call i32 @clock_gettime(i32 %32, %struct.timespec* %2)
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %36, %31
%39 = load i32, i32* @_SC_CLK_TCK
%40 = call i32 @sysconf(i32 %39)
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = call i32 @times(%struct.tms* %3)
store i32 %42, i32* %5
%43 = load i32, i32* %5
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45, %38
%48 = load i64, i64* %4
%49 = trunc i64 %48 to i32
%50 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %49)
%51 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%52 = load i32, i32* %51
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%54 = load i32, i32* %53
%55 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %52, i32 %54)
%56 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%57 = load i64, i64* %56
%58 = trunc i64 %57 to i32
%59 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%60 = load i64, i64* %59
%61 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %58, i64 %60)
%62 = getelementptr inbounds %struct.tms, %struct.tms* %3, i32 0, i32 1
%63 = load i32, i32* %62
%64 = getelementptr inbounds %struct.tms, %struct.tms* %3, i32 0, i32 0
%65 = load i32, i32* %64
%66 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %63, i32 %65)
store i32 0, i32* %6
br label %67
67: ; preds = %95, %47
%68 = load i32, i32* %6
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [7 x i32], [7 x i32]* %9, i64 0, i64 %69
%71 = load i32, i32* %70
%72 = icmp ne i32 %71, -1
br i1 %72, label %73, label %98
73: ; preds = %67
%74 = load i32, i32* %6
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [7 x i32], [7 x i32]* %9, i64 0, i64 %75
%77 = load i32, i32* %76
%78 = call i32 @clock_getres(i32 %77, %struct.timespec* %10)
store i32 %78, i32* %11
%79 = load i32, i32* %11
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %73
%82 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
br label %94
83: ; preds = %73
%84 = load i32, i32* %6
%85 = load i32, i32* %6
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [7 x i32], [7 x i32]* %9, i64 0, i64 %86
%88 = load i32, i32* %87
%89 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 1
%90 = load i64, i64* %89
%91 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
%92 = load i64, i64* %91
%93 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i32 %84, i32 %88, i64 %90, i64 %92)
br label %94
94: ; preds = %83, %81
br label %95
95: ; preds = %94
%96 = load i32, i32* %6
%97 = add nsw i32 %96, 1
store i32 %97, i32* %6
br label %67
98: ; preds = %67
store i32 0, i32* %6
br label %99
99: ; preds = %122, %98
%100 = load i32, i32* %6
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds [7 x i32], [7 x i32]* %9, i64 0, i64 %101
%103 = load i32, i32* %102
%104 = icmp ne i32 %103, -1
br i1 %104, label %105, label %125
105: ; preds = %99
%106 = load i32, i32* %6
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds [7 x i32], [7 x i32]* %9, i64 0, i64 %107
%109 = load i32, i32* %108
%110 = load i32, i32* %6
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds [10 x %struct.timespec], [10 x %struct.timespec]* %7, i64 0, i64 %111
%113 = call i32 @clock_gettime(i32 %109, %struct.timespec* %112)
store i32 %113, i32* %5
%114 = load i32, i32* %5
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %121
116: ; preds = %105
%117 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%118 = load i32, i32* %6
%119 = load i32, i32* %5
%120 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %118, i32 %119)
br label %121
121: ; preds = %116, %105
br label %122
122: ; preds = %121
%123 = load i32, i32* %6
%124 = add nsw i32 %123, 1
store i32 %124, i32* %6
br label %99
125: ; preds = %99
%126 = call i32 @sleep(i32 5)
store i32 0, i32* %6
br label %127
127: ; preds = %150, %125
%128 = load i32, i32* %6
%129 = sext i32 %128 to i64
%130 = getelementptr inbounds [7 x i32], [7 x i32]* %9, i64 0, i64 %129
%131 = load i32, i32* %130
%132 = icmp ne i32 %131, -1
br i1 %132, label %133, label %153
133: ; preds = %127
%134 = load i32, i32* %6
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds [7 x i32], [7 x i32]* %9, i64 0, i64 %135
%137 = load i32, i32* %136
%138 = load i32, i32* %6
%139 = sext i32 %138 to i64
%140 = getelementptr inbounds [10 x %struct.timespec], [10 x %struct.timespec]* %8, i64 0, i64 %139
%141 = call i32 @clock_gettime(i32 %137, %struct.timespec* %140)
store i32 %141, i32* %5
%142 = load i32, i32* %5
%143 = icmp eq i32 %142, -1
br i1 %143, label %144, label %149
144: ; preds = %133
%145 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%146 = load i32, i32* %6
%147 = load i32, i32* %5
%148 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %146, i32 %147)
br label %149
149: ; preds = %144, %133
br label %150
150: ; preds = %149
%151 = load i32, i32* %6
%152 = add nsw i32 %151, 1
store i32 %152, i32* %6
br label %127
153: ; preds = %127
store i32 0, i32* %6
br label %154
154: ; preds = %189, %153
%155 = load i32, i32* %6
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds [7 x i32], [7 x i32]* %9, i64 0, i64 %156
%158 = load i32, i32* %157
%159 = icmp ne i32 %158, -1
br i1 %159, label %160, label %192
160: ; preds = %154
%161 = load i32, i32* %6
%162 = load i32, i32* %6
%163 = sext i32 %162 to i64
%164 = getelementptr inbounds [7 x i32], [7 x i32]* %9, i64 0, i64 %163
%165 = load i32, i32* %164
%166 = load i32, i32* %6
%167 = sext i32 %166 to i64
%168 = getelementptr inbounds [10 x %struct.timespec], [10 x %struct.timespec]* %8, i64 0, i64 %167
%169 = getelementptr inbounds %struct.timespec, %struct.timespec* %168, i32 0, i32 1
%170 = load i64, i64* %169
%171 = load i32, i32* %6
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds [10 x %struct.timespec], [10 x %struct.timespec]* %7, i64 0, i64 %172
%174 = getelementptr inbounds %struct.timespec, %struct.timespec* %173, i32 0, i32 1
%175 = load i64, i64* %174
%176 = sub nsw i64 %170, %175
%177 = load i32, i32* %6
%178 = sext i32 %177 to i64
%179 = getelementptr inbounds [10 x %struct.timespec], [10 x %struct.timespec]* %8, i64 0, i64 %178
%180 = getelementptr inbounds %struct.timespec, %struct.timespec* %179, i32 0, i32 0
%181 = load i64, i64* %180
%182 = load i32, i32* %6
%183 = sext i32 %182 to i64
%184 = getelementptr inbounds [10 x %struct.timespec], [10 x %struct.timespec]* %7, i64 0, i64 %183
%185 = getelementptr inbounds %struct.timespec, %struct.timespec* %184, i32 0, i32 0
%186 = load i64, i64* %185
%187 = sub nsw i64 %181, %186
%188 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i32 %161, i32 %165, i64 %176, i64 %187)
br label %189
189: ; preds = %160
%190 = load i32, i32* %6
%191 = add nsw i32 %190, 1
store i32 %191, i32* %6
br label %154
192: ; preds = %154
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.timespec = type { i64, i64 }
%struct.tms = type { i32, i32 }
@CLOCK_REALTIME = global i32 0
@CLOCK_MONOTONIC = global i32 0
@CLOCK_MONOTONIC_RAW = global i32 0
@CLOCK_MONOTONIC_COARSE = global i32 0
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
@CLOCK_THREAD_CPUTIME_ID = global i32 0
@.str = [19 x i8] c"gettimeofday fail \00"
@.str.1 = [20 x i8] c"clock gettime fail \00"
@.str.2 = [17 x i8] c"clk per sec %ld\0A\00"
@_SC_CLK_TCK = global i32 0
@.str.3 = [12 x i8] c"times fail \00"
@.str.4 = [17 x i8] c"current time %d\0A\00"
@.str.5 = [21 x i8] c"tv sec %ld usec %ld\0A\00"
@.str.6 = [21 x i8] c"tp sec %ld nsec %ld\0A\00"
@.str.7 = [22 x i8] c"tms sec %ld usec %ld\0A\00"
@.str.8 = [13 x i8] c"clock_getres\00"
@.str.9 = [30 x i8] c"%d clock=%d sec=%ld nsec=%ld\0A\00"
@.str.10 = [13 x i8] c"gettime fail\00"
@.str.11 = [7 x i8] c"%d %d\0A\00"
@.str.12 = [20 x i8] c"%d | %d | %ld %ld \0A\00"
define i32 @time2_test() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timespec
%3 = alloca %struct.tms
%4 = alloca [10 x %struct.timespec]
%5 = alloca [10 x %struct.timespec]
%6 = alloca [7 x i32]
%7 = alloca %struct.timespec
%8 = bitcast %struct.timeval* %1 to i8*
%9 = bitcast %struct.timespec* %2 to i8*
%10 = bitcast %struct.tms* %3 to i8*
%11 = bitcast [10 x %struct.timespec]* %4 to i8*
%12 = bitcast [10 x %struct.timespec]* %5 to i8*
%13 = bitcast [7 x i32]* %6 to i8*
%14 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 0
%15 = load i32, i32* @CLOCK_REALTIME
store i32 %15, i32* %14
%16 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 1
%17 = load i32, i32* @CLOCK_MONOTONIC
store i32 %17, i32* %16
%18 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 2
%19 = load i32, i32* @CLOCK_MONOTONIC_RAW
store i32 %19, i32* %18
%20 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 3
%21 = load i32, i32* @CLOCK_MONOTONIC_COARSE
store i32 %21, i32* %20
%22 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 4
%23 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
store i32 %23, i32* %22
%24 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 5
%25 = load i32, i32* @CLOCK_THREAD_CPUTIME_ID
store i32 %25, i32* %24
%26 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 6
store i32 -1, i32* %26
%27 = tail call i64 @time(i32* null)
%28 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%29 = icmp eq i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %0
%31 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %30, %0
%33 = load i32, i32* @CLOCK_REALTIME
%34 = call i32 @clock_gettime(i32 %33, %struct.timespec* %2)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %36, %32
%39 = load i32, i32* @_SC_CLK_TCK
%40 = call i32 @sysconf(i32 %39)
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = call i32 @times(%struct.tms* %3)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %44, %38
%47 = trunc i64 %27 to i32
%48 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %47)
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%50 = load i32, i32* %49
%51 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%52 = load i32, i32* %51
%53 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %50, i32 %52)
%54 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%55 = load i64, i64* %54
%56 = trunc i64 %55 to i32
%57 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%58 = load i64, i64* %57
%59 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %56, i64 %58)
%60 = getelementptr inbounds %struct.tms, %struct.tms* %3, i64 0, i32 1
%61 = load i32, i32* %60
%62 = getelementptr inbounds %struct.tms, %struct.tms* %3, i64 0, i32 0
%63 = load i32, i32* %62
%64 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %61, i32 %63)
%65 = icmp eq i32 %15, -1
br i1 %65, label %103, label %66
66: ; preds = %46
%67 = bitcast %struct.timespec* %7 to i8*
%68 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i64 0, i32 1
%69 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i64 0, i32 0
br label %71
70: ; preds = %83
br i1 %65, label %103, label %88
71: ; preds = %66, %83
%72 = phi i64 [ 0, %66 ], [ %84, %83 ]
%73 = phi i32 [ %15, %66 ], [ %86, %83 ]
%74 = call i32 @clock_getres(i32 %73, %struct.timespec* %7)
%75 = icmp eq i32 %74, 0
br i1 %75, label %78, label %76
76: ; preds = %71
%77 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
br label %83
78: ; preds = %71
%79 = load i64, i64* %68
%80 = load i64, i64* %69
%81 = trunc i64 %72 to i32
%82 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i32 %81, i32 %73, i64 %79, i64 %80)
br label %83
83: ; preds = %78, %76
%84 = add nuw i64 %72, 1
%85 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 %84
%86 = load i32, i32* %85
%87 = icmp eq i32 %86, -1
br i1 %87, label %70, label %71
88: ; preds = %70, %98
%89 = phi i64 [ %99, %98 ], [ 0, %70 ]
%90 = phi i32 [ %101, %98 ], [ %15, %70 ]
%91 = getelementptr inbounds [10 x %struct.timespec], [10 x %struct.timespec]* %4, i64 0, i64 %89
%92 = call i32 @clock_gettime(i32 %90, %struct.timespec* %91)
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %98
94: ; preds = %88
%95 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%96 = trunc i64 %89 to i32
%97 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %96, i32 -1)
br label %98
98: ; preds = %88, %94
%99 = add nuw i64 %89, 1
%100 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 %99
%101 = load i32, i32* %100
%102 = icmp eq i32 %101, -1
br i1 %102, label %105, label %88
103: ; preds = %70, %46
%104 = call i32 @sleep(i32 5)
br label %142
105: ; preds = %98
%106 = call i32 @sleep(i32 5)
br i1 %65, label %142, label %108
107: ; preds = %118
br i1 %65, label %142, label %123
108: ; preds = %105, %118
%109 = phi i64 [ %119, %118 ], [ 0, %105 ]
%110 = phi i32 [ %121, %118 ], [ %15, %105 ]
%111 = getelementptr inbounds [10 x %struct.timespec], [10 x %struct.timespec]* %5, i64 0, i64 %109
%112 = call i32 @clock_gettime(i32 %110, %struct.timespec* %111)
%113 = icmp eq i32 %112, -1
br i1 %113, label %114, label %118
114: ; preds = %108
%115 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%116 = trunc i64 %109 to i32
%117 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %116, i32 -1)
br label %118
118: ; preds = %108, %114
%119 = add nuw i64 %109, 1
%120 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 %119
%121 = load i32, i32* %120
%122 = icmp eq i32 %121, -1
br i1 %122, label %107, label %108
123: ; preds = %107, %123
%124 = phi i64 [ %138, %123 ], [ 0, %107 ]
%125 = phi i32 [ %140, %123 ], [ %15, %107 ]
%126 = getelementptr inbounds [10 x %struct.timespec], [10 x %struct.timespec]* %5, i64 0, i64 %124, i32 1
%127 = load i64, i64* %126
%128 = getelementptr inbounds [10 x %struct.timespec], [10 x %struct.timespec]* %4, i64 0, i64 %124, i32 1
%129 = load i64, i64* %128
%130 = sub nsw i64 %127, %129
%131 = getelementptr inbounds [10 x %struct.timespec], [10 x %struct.timespec]* %5, i64 0, i64 %124, i32 0
%132 = load i64, i64* %131
%133 = getelementptr inbounds [10 x %struct.timespec], [10 x %struct.timespec]* %4, i64 0, i64 %124, i32 0
%134 = load i64, i64* %133
%135 = sub nsw i64 %132, %134
%136 = trunc i64 %124 to i32
%137 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i32 %136, i32 %125, i64 %130, i64 %135)
%138 = add nuw i64 %124, 1
%139 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 %138
%140 = load i32, i32* %139
%141 = icmp eq i32 %140, -1
br i1 %141, label %142, label %123
142: ; preds = %123, %105, %103, %107
ret i32 0
}