#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 timeb {
  scalar_t__ time;
  scalar_t__ millitm;
};

/* Variables and functions */
scalar_t__ ftime(struct timeb *);
int /*<<< orphan*/ printf(char *);
int do_test(void) {
  struct timeb prev, curr = {.time = 0, .millitm = 0};
  int sec = 0;
  while (sec != 3) {
    prev = curr;
    if (ftime(&curr)) {
      printf("ftime returned an error\n");
      return 1;
    }
    if (curr.time < prev.time) {
      printf("ftime's time flowed backwards\n");
      return 1;
    }
    if (curr.time == prev.time && curr.millitm < prev.millitm) {
      printf("ftime's millitm flowed backwards\n");
      return 1;
    }
    if (curr.time > prev.time)
      sec++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3,-0x2c(%rbp)
je     120a <do_test+0xda>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
call   1050 <ftime@plt>
cmp    $0x0,%rax
je     1194 <do_test+0x64>
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1211 <do_test+0xe1>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11ba <do_test+0x8a>
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1211 <do_test+0xe1>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11ee <do_test+0xbe>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11ee <do_test+0xbe>
lea    0xe5b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1211 <do_test+0xe1>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jle    1205 <do_test+0xd5>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114f <do_test+0x1f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
xor    %ebx,%ebx
mov    %rsp,%r13
lea    0xefe(%rip),%r14
lea    0xeb8(%rip),%r12
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    1165 <do_test+0x45>
nop
xor    %edx,%edx
cmp    %r15,%rax
setg   %dl
add    %edx,%ebp
mov    %rcx,%rbx
mov    %rax,%r15
cmp    $0x3,%ebp
je     118c <do_test+0x6c>
mov    %r13,%rdi
call   1040 <ftime@plt>
test   %rax,%rax
jne    1197 <do_test+0x77>
mov    (%rsp),%rax
cmp    %r15,%rax
jl     1190 <do_test+0x70>
mov    0x8(%rsp),%rcx
jne    1150 <do_test+0x30>
cmp    %rbx,%rcx
jge    1150 <do_test+0x30>
mov    %r12,%r14
jmp    1197 <do_test+0x77>
xor    %eax,%eax
jmp    11a4 <do_test+0x84>
lea    0xe8a(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeb = type { i64, i64 }
@.str = [25 x i8] c"ftime returned an error\0A\00"
@.str.1 = [31 x i8] c"ftime's time flowed backwards\0A\00"
@.str.2 = [34 x i8] c"ftime's millitm flowed backwards\0A\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca %struct.timeb
%3 = alloca %struct.timeb
%4 = alloca i32
%5 = bitcast %struct.timeb* %3 to i8*
store i32 0, i32* %4
br label %6
6: ; preds = %47, %0
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 3
br i1 %8, label %9, label %48
9: ; preds = %6
%10 = bitcast %struct.timeb* %2 to i8*
%11 = bitcast %struct.timeb* %3 to i8*
%12 = call i64 @ftime(%struct.timeb* %3)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %49
16: ; preds = %9
%17 = getelementptr inbounds %struct.timeb, %struct.timeb* %3, i32 0, i32 0
%18 = load i64, i64* %17
%19 = getelementptr inbounds %struct.timeb, %struct.timeb* %2, i32 0, i32 0
%20 = load i64, i64* %19
%21 = icmp slt i64 %18, %20
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %49
24: ; preds = %16
%25 = getelementptr inbounds %struct.timeb, %struct.timeb* %3, i32 0, i32 0
%26 = load i64, i64* %25
%27 = getelementptr inbounds %struct.timeb, %struct.timeb* %2, i32 0, i32 0
%28 = load i64, i64* %27
%29 = icmp eq i64 %26, %28
br i1 %29, label %30, label %38
30: ; preds = %24
%31 = getelementptr inbounds %struct.timeb, %struct.timeb* %3, i32 0, i32 1
%32 = load i64, i64* %31
%33 = getelementptr inbounds %struct.timeb, %struct.timeb* %2, i32 0, i32 1
%34 = load i64, i64* %33
%35 = icmp slt i64 %32, %34
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %49
38: ; preds = %30, %24
%39 = getelementptr inbounds %struct.timeb, %struct.timeb* %3, i32 0, i32 0
%40 = load i64, i64* %39
%41 = getelementptr inbounds %struct.timeb, %struct.timeb* %2, i32 0, i32 0
%42 = load i64, i64* %41
%43 = icmp sgt i64 %40, %42
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
store i32 %46, i32* %4
br label %47
47: ; preds = %44, %38
br label %6
48: ; preds = %6
store i32 0, i32* %1
br label %49
49: ; preds = %48, %36, %22, %14
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
%struct.timeb = type { i64, i64 }
@str = [33 x i8] c"ftime's millitm flowed backwards\00"
@str.3 = [30 x i8] c"ftime's time flowed backwards\00"
@str.4 = [24 x i8] c"ftime returned an error\00"
define i32 @do_test() {
%1 = alloca %struct.timeb
%2 = bitcast %struct.timeb* %1 to i8*
%3 = getelementptr inbounds %struct.timeb, %struct.timeb* %1, i64 0, i32 0
%4 = getelementptr inbounds %struct.timeb, %struct.timeb* %1, i64 0, i32 1
br label %5
5: ; preds = %0, %19
%6 = phi i64 [ 0, %0 ], [ %16, %19 ]
%7 = phi i64 [ 0, %0 ], [ %12, %19 ]
%8 = phi i32 [ 0, %0 ], [ %22, %19 ]
%9 = call i64 @ftime(%struct.timeb* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %5
%12 = load i64, i64* %3
%13 = icmp slt i64 %12, %7
br i1 %13, label %24, label %14
14: ; preds = %11
%15 = icmp eq i64 %12, %7
%16 = load i64, i64* %4
%17 = icmp slt i64 %16, %6
%18 = select i1 %15, i1 %17, i1 false
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = icmp sgt i64 %12, %7
%21 = zext i1 %20 to i32
%22 = add nuw nsw i32 %8, %21
%23 = icmp eq i32 %22, 3
br i1 %23, label %27, label %5
24: ; preds = %14, %11, %5
%25 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @str.4, i64 0, i64 0), %5 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @str.3, i64 0, i64 0), %11 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0), %14 ]
%26 = call i32 @puts(i8* dereferenceable(1) %25)
br label %27
27: ; preds = %19, %24
%28 = phi i32 [ 1, %24 ], [ 0, %19 ]
ret i32 %28
}