#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 timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, long, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ timersub(struct timeval *, struct timeval *,
                            struct timeval *);
int main(int argc, char **argv) {
  int sleep_seconds;
  struct timeval tval_before, tval_after, tval_result;
  if (argc > 1) {
    sleep_seconds = atoi(argv[1]);
  } else {
    sleep_seconds = 1;
  }
  gettimeofday(&tval_before, NULL);
  printf("will sleep %d seconds\n", sleep_seconds);
  sleep(sleep_seconds);
  gettimeofday(&tval_after, NULL);
  timersub(&tval_after, &tval_before, &tval_result);
  printf("Time elapsed: %ld.%06ld in %d sleep\n", (long int)tval_result.tv_sec,
         (long int)tval_result.tv_usec, sleep_seconds);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1185 <main+0x35>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    118c <main+0x3c>
movl   $0x1,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movslq -0x14(%rbp),%rsi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <sleep@plt>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x38(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   1060 <timersub@plt>
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    $0x1,%ebx
cmp    $0x2,%edi
jl     116e <main+0x1e>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%ebx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movslq %ebx,%rbx
lea    0xe79(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
call   1070 <sleep@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    %rsp,%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <timersub@plt>
mov    (%rsp),%rdx
mov    0x8(%rsp),%rsi
lea    0xe52(%rip),%rdi
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [23 x i8] c"will sleep %d seconds\0A\00"
@.str.1 = [37 x i8] c"Time elapsed: %ld.%06ld in %d sleep\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
br label %18
17: ; preds = %2
store i32 1, i32* %6
br label %18
18: ; preds = %17, %12
%19 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i64 %21)
%23 = load i32, i32* %6
%24 = call i32 @sleep(i32 %23)
%25 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%26 = call i32 @timersub(%struct.timeval* %8, %struct.timeval* %7, %struct.timeval* %9)
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%28 = load i64, i64* %27
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%30 = load i64, i64* %29
%31 = load i32, i32* %6
%32 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i64 %28, i64 %30, i32 %31)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [23 x i8] c"will sleep %d seconds\0A\00"
@.str.1 = [37 x i8] c"Time elapsed: %ld.%06ld in %d sleep\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = bitcast %struct.timeval* %5 to i8*
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
br label %14
14: ; preds = %2, %10
%15 = phi i32 [ %13, %10 ], [ 1, %2 ]
%16 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%17 = sext i32 %15 to i64
%18 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i64 %17)
%19 = tail call i32 @sleep(i32 %15)
%20 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%21 = call i32 @timersub(%struct.timeval* %4, %struct.timeval* %3, %struct.timeval* %5)
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%23 = load i64, i64* %22
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%25 = load i64, i64* %24
%26 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i64 %23, i64 %25, i32 %15)
ret i32 0
}