#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 stat {
  scalar_t__ st_mtime;
};

/* Variables and functions */
scalar_t__ atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int sleep(scalar_t__);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
scalar_t__ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ touch(char *);
int main(int argc, char *argv[]) {
  time_t diff_time, target_time;
  struct stat st;
  int ret;
  if (argc != 3) {
    fprintf(stderr, "usage: %s target_sleep_time control_file\n", argv[0]);
    exit(1);
  }
  if (stat(argv[2], &st)) {
    fprintf(stderr, "Failed to stat %s\n", argv[2]);
    exit(2);
  }
  target_time = atoi(argv[1]);
  diff_time = time(NULL) - st.st_mtime;
  fprintf(stderr, "stat %s: diff %d sleep %d\n", argv[0], (int)diff_time,
          (int)(target_time - diff_time));
  if (diff_time >= target_time) {
    touch(argv[2]);
    return (0);
  }
  ret = sleep(target_time - diff_time);
  touch(argv[2]);
  return ret;
}


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)
cmpl   $0x3,-0x8(%rbp)
je     11b8 <main+0x48>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
je     11fc <main+0x8c>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
sub    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    %eax,%r8d
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jl     1274 <main+0x104>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <touch@plt>
movl   $0x0,-0x4(%rbp)
jmp    1297 <main+0x127>
mov    -0x20(%rbp),%rdi
sub    -0x18(%rbp),%rdi
call   1090 <sleep@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <touch@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
cmp    $0x3,%edi
jne    11fc <main+0x8c>
mov    0x10(%r15),%rdi
mov    %rsp,%rsi
call   1050 <stat@plt>
test   %rax,%rax
jne    1220 <main+0xb0>
mov    0x8(%r15),%rdi
call   1070 <atoi@plt>
mov    %rax,%r12
xor    %r14d,%r14d
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,%rbx
sub    (%rsp),%rbx
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
mov    %r12,%r8
sub    %rbx,%r8
lea    0xe72(%rip),%rsi
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
sub    %rbx,%r12
jle    11e4 <main+0x74>
mov    %r12,%rdi
call   1090 <sleep@plt>
mov    %eax,%r14d
mov    0x10(%r15),%rdi
call   1030 <touch@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xdf1(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r15),%rdx
lea    0xdf6(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [42 x i8] c"usage: %s target_sleep_time control_file\0A\00"
@.str.1 = [19 x i8] c"Failed to stat %s\0A\00"
@.str.2 = [27 x i8] c"stat %s: diff %d sleep %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca %struct.stat
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i64 @stat(i8* %22, %struct.stat* %8)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 2)
unreachable
32: ; preds = %19
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i64 @atoi(i8* %35)
store i64 %36, i64* %7
%37 = call i64 @time(i32* null)
%38 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%39 = load i64, i64* %38
%40 = sub nsw i64 %37, %39
store i64 %40, i64* %6
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = load i64, i64* %6
%46 = trunc i64 %45 to i32
%47 = load i64, i64* %7
%48 = load i64, i64* %6
%49 = sub nsw i64 %47, %48
%50 = trunc i64 %49 to i32
%51 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %44, i32 %46, i32 %50)
%52 = load i64, i64* %6
%53 = load i64, i64* %7
%54 = icmp sge i64 %52, %53
br i1 %54, label %55, label %60
55: ; preds = %32
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 2
%58 = load i8*, i8** %57
%59 = call i32 @touch(i8* %58)
store i32 0, i32* %3
br label %70
60: ; preds = %32
%61 = load i64, i64* %7
%62 = load i64, i64* %6
%63 = sub nsw i64 %61, %62
%64 = call i32 @sleep(i64 %63)
store i32 %64, i32* %9
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 2
%67 = load i8*, i8** %66
%68 = call i32 @touch(i8* %67)
%69 = load i32, i32* %9
store i32 %69, i32* %3
br label %70
70: ; preds = %60, %55
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [42 x i8] c"usage: %s target_sleep_time control_file\0A\00"
@.str.1 = [19 x i8] c"Failed to stat %s\0A\00"
@.str.2 = [27 x i8] c"stat %s: diff %d sleep %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = call i64 @stat(i8* %13, %struct.stat* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 2)
unreachable
21: ; preds = %11
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @atoi(i8* %23)
%25 = call i64 @time(i32* null)
%26 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%27 = load i64, i64* %26
%28 = sub nsw i64 %25, %27
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %1
%31 = trunc i64 %28 to i32
%32 = sub nsw i64 %24, %28
%33 = trunc i64 %32 to i32
%34 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %30, i32 %31, i32 %33)
%35 = icmp sgt i64 %24, %28
br i1 %35, label %36, label %38
36: ; preds = %21
%37 = call i32 @sleep(i64 %32)
br label %38
38: ; preds = %21, %36
%39 = phi i32 [ %37, %36 ], [ 0, %21 ]
%40 = load i8*, i8** %12
%41 = call i32 @touch(i8* %40)
ret i32 %39
}