#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_atime;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int stat(char const *, struct stat *);
void signal_wait(const char *file, time_t *orig_atime) {
  struct stat st;
  while (1) {
    if (-1 == stat(file, &st)) {
      perror("stat");
      printf("file: %s\n\n", file);
      exit(-1);
    };
    if (st.st_atime > *orig_atime) {
      *orig_atime = st.st_atime;
      break;
    }
    sleep(1);
    printf("waitting...\n");
  }
}


x86 assembly (clang, -O0):
<signal_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11a4 <signal_wait+0x54>
lea    0xe7d(%rip),%rdi
call   1050 <perror@plt>
mov    -0x8(%rbp),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jle    11c5 <signal_wait+0x75>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    11e2 <signal_wait+0x92>
mov    $0x1,%edi
call   1070 <sleep@plt>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1160 <signal_wait+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_wait>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     11bb <signal_wait+0x5b>
lea    0xe8e(%rip),%r15
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rsp),%rax
cmp    (%rbx),%rax
jg     11e2 <signal_wait+0x82>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    1190 <signal_wait+0x30>
lea    0xe3e(%rip),%rdi
call   1060 <perror@plt>
lea    0xe37(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    %rax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [5 x i8] c"stat\00"
@.str.1 = [11 x i8] c"file: %s\0A\0A\00"
@.str.2 = [13 x i8] c"waitting...\0A\00"
define void @signal_wait(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca %struct.stat
store i8* %0, i8** %3
store i64* %1, i64** %4
br label %6
6: ; preds = %2, %25
%7 = load i8*, i8** %3
%8 = call i32 @stat(i8* %7, %struct.stat* %5)
%9 = icmp eq i32 -1, %8
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = load i8*, i8** %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %6
%16 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%17 = load i64, i64* %16
%18 = load i64*, i64** %4
%19 = load i64, i64* %18
%20 = icmp sgt i64 %17, %19
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%23 = load i64, i64* %22
%24 = load i64*, i64** %4
store i64 %23, i64* %24
br label %28
25: ; preds = %15
%26 = call i32 @sleep(i32 1)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %6
28: ; preds = %21
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [5 x i8] c"stat\00"
@.str.1 = [11 x i8] c"file: %s\0A\0A\00"
@str = [12 x i8] c"waitting...\00"
define void @signal_wait(i8* %0, i64* nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i32 @stat(i8* %0, %struct.stat* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
br label %13
9: ; preds = %18, %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %7, %18
%14 = load i64, i64* %8
%15 = load i64, i64* %1
%16 = icmp sgt i64 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %13
store i64 %14, i64* %1
ret void
18: ; preds = %13
%19 = tail call i32 @sleep(i32 1)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%21 = call i32 @stat(i8* %0, %struct.stat* %3)
%22 = icmp eq i32 %21, -1
br i1 %22, label %9, label %13
}