#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 *, char const *);
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);
  }
}


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    11a2 <signal_wait+0x52>
lea    0xe7d(%rip),%rdi
call   1050 <perror@plt>
mov    -0x8(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jle    11c3 <signal_wait+0x73>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    11d2 <signal_wait+0x82>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    1160 <signal_wait+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_wait>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
je     11a4 <signal_wait+0x54>
lea    0x8(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x8(%rsp),%rax
cmp    (%rbx),%rax
jg     11c9 <signal_wait+0x79>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    1180 <signal_wait+0x30>
lea    0xe55(%rip),%rdi
call   1050 <perror@plt>
lea    0xe4e(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    %rax,(%rbx)
add    $0x10,%rsp
pop    %rbx
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"
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 @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 %27
25: ; preds = %15
%26 = call i32 @sleep(i32 1)
br label %6
27: ; 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"
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 @printf(i8* 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 = call i32 @stat(i8* %0, %struct.stat* %3)
%21 = icmp eq i32 %20, -1
br i1 %21, label %9, label %13
}