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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ ftime(struct timeb *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int busySeconds = 1;
  int dummyNum = 2;
  int i = 0, duration;
  struct timeb beg, end;
  if (argc > 1) {
    busySeconds = atoi(argv[1]);
  }
  printf("Going to be busy for %d seconds\n", busySeconds);
  ftime(&beg);
  while (1) {
    for (i = 0; i < 1000; i++)
      dummyNum += i * i;
    ftime(&end);
    duration =
        ((end.millitm + end.time * 1000) - (beg.millitm + beg.time * 1000));
    if (duration > busySeconds * 1000)
      break;
  }
  printf("Waking up\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x2,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1175 <main+0x45>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x28(%rbp),%rdi
call   1050 <ftime@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jge    11be <main+0x8e>
mov    -0x1c(%rbp),%eax
imul   -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1196 <main+0x66>
lea    -0x30(%rbp),%rdi
call   1050 <ftime@plt>
mov    -0x30(%rbp),%eax
imul   $0x3e8,-0x2c(%rbp),%ecx
add    %ecx,%eax
mov    -0x28(%rbp),%ecx
imul   $0x3e8,-0x24(%rbp),%edx
add    %edx,%ecx
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
imul   $0x3e8,-0x14(%rbp),%ecx
cmp    %ecx,%eax
jle    11fb <main+0xcb>
jmp    1200 <main+0xd0>
jmp    118f <main+0x5f>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%ebx
cmp    $0x2,%edi
jl     115b <main+0x1b>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%ebx
lea    0xe9e(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rdi
call   1060 <ftime@plt>
imul   $0x3e8,%ebx,%ebp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <ftime@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
sub    0x14(%rsp),%ecx
imul   $0x3e8,%ecx,%ecx
sub    0x10(%rsp),%eax
add    %ecx,%eax
cmp    %ebp,%eax
jle    1180 <main+0x40>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeb = type { i32, i32 }
@.str = [33 x i8] c"Going to be busy for %d seconds\0A\00"
@.str.1 = [11 x i8] c"Waking up\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.timeb
%11 = alloca %struct.timeb
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
store i32 2, i32* %7
store i32 0, i32* %8
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
br label %19
19: ; preds = %14, %2
%20 = load i32, i32* %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = call i32 @ftime(%struct.timeb* %10)
br label %23
23: ; preds = %19, %56
store i32 0, i32* %8
br label %24
24: ; preds = %33, %23
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 1000
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load i32, i32* %8
%29 = load i32, i32* %8
%30 = mul nsw i32 %28, %29
%31 = load i32, i32* %7
%32 = add nsw i32 %31, %30
store i32 %32, i32* %7
br label %33
33: ; preds = %27
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %24
36: ; preds = %24
%37 = call i32 @ftime(%struct.timeb* %11)
%38 = getelementptr inbounds %struct.timeb, %struct.timeb* %11, i32 0, i32 0
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.timeb, %struct.timeb* %11, i32 0, i32 1
%41 = load i32, i32* %40
%42 = mul nsw i32 %41, 1000
%43 = add nsw i32 %39, %42
%44 = getelementptr inbounds %struct.timeb, %struct.timeb* %10, i32 0, i32 0
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.timeb, %struct.timeb* %10, i32 0, i32 1
%47 = load i32, i32* %46
%48 = mul nsw i32 %47, 1000
%49 = add nsw i32 %45, %48
%50 = sub nsw i32 %43, %49
store i32 %50, i32* %9
%51 = load i32, i32* %9
%52 = load i32, i32* %6
%53 = mul nsw i32 %52, 1000
%54 = icmp sgt i32 %51, %53
br i1 %54, label %55, label %56
55: ; preds = %36
br label %57
56: ; preds = %36
br label %23
57: ; preds = %55
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.timeb = type { i32, i32 }
@.str = [33 x i8] c"Going to be busy for %d seconds\0A\00"
@str = [10 x i8] c"Waking up\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeb
%4 = alloca %struct.timeb
%5 = bitcast %struct.timeb* %3 to i8*
%6 = bitcast %struct.timeb* %4 to i8*
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
br label %12
12: ; preds = %8, %2
%13 = phi i32 [ %11, %8 ], [ 1, %2 ]
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @ftime(%struct.timeb* %3)
%16 = getelementptr inbounds %struct.timeb, %struct.timeb* %4, i64 0, i32 0
%17 = getelementptr inbounds %struct.timeb, %struct.timeb* %4, i64 0, i32 1
%18 = getelementptr inbounds %struct.timeb, %struct.timeb* %3, i64 0, i32 0
%19 = getelementptr inbounds %struct.timeb, %struct.timeb* %3, i64 0, i32 1
%20 = mul nsw i32 %13, 1000
br label %21
21: ; preds = %21, %12
%22 = call i32 @ftime(%struct.timeb* %4)
%23 = load i32, i32* %16
%24 = load i32, i32* %17
%25 = load i32, i32* %18
%26 = load i32, i32* %19
%27 = sub i32 %24, %26
%28 = mul i32 %27, 1000
%29 = sub i32 %23, %25
%30 = add i32 %29, %28
%31 = icmp sgt i32 %30, %20
br i1 %31, label %32, label %21
32: ; preds = %21
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
ret i32 0
}