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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__);
int fstat(int, struct stat *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int check_changes(int fd, struct stat *prev_stat) {
  struct stat new_stat;
  int ret;
  ret = fstat(fd, &new_stat);
  if (ret) {
    perror("fstat");
    return ret;
  }
  if (prev_stat->st_mtime == new_stat.st_mtime) {
    fprintf(stderr,
            "mtime has not been changed. "
            "mtime is %ld\n",
            prev_stat->st_mtime);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_changes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <fstat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     116f <check_changes+0x3f>
lea    0xea1(%rip),%rdi
call   1040 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11af <check_changes+0x7f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
jne    11a8 <check_changes+0x78>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe6f(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <check_changes+0x7f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_changes>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rsp,%rsi
call   1050 <fstat@plt>
test   %eax,%eax
jne    1172 <check_changes+0x42>
mov    (%r14),%rdx
xor    %ebx,%ebx
cmp    (%rsp),%rdx
jne    1168 <check_changes+0x38>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %eax,%ebx
lea    0xe85(%rip),%rdi
call   1040 <perror@plt>
jmp    1168 <check_changes+0x38>

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [6 x i8] c"fstat\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"mtime has not been changed. mtime is %ld\0A\00"
define i32 @check_changes(i32 %0, %struct.stat* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.stat*
%6 = alloca %struct.stat
%7 = alloca i32
store i32 %0, i32* %4
store %struct.stat* %1, %struct.stat** %5
%8 = load i32, i32* %4
%9 = call i32 @fstat(i32 %8, %struct.stat* %6)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* %7
store i32 %14, i32* %3
br label %29
15: ; preds = %2
%16 = load %struct.stat*, %struct.stat** %5
%17 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 0
%18 = load i64, i64* %17
%19 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%20 = load i64, i64* %19
%21 = icmp eq i64 %18, %20
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = load %struct.stat*, %struct.stat** %5
%25 = getelementptr inbounds %struct.stat, %struct.stat* %24, i32 0, i32 0
%26 = load i64, i64* %25
%27 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 %26)
store i32 -1, i32* %3
br label %29
28: ; preds = %15
store i32 0, i32* %3
br label %29
29: ; preds = %28, %22, %12
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [6 x i8] c"fstat\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"mtime has not been changed. mtime is %ld\0A\00"
define i32 @check_changes(i32 %0, %struct.stat* nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i32 @fstat(i32 %0, %struct.stat* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %18
9: ; preds = %2
%10 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%13 = load i64, i64* %12
%14 = icmp eq i64 %11, %13
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 %11)
br label %18
18: ; preds = %9, %15, %7
%19 = phi i32 [ %5, %7 ], [ -1, %15 ], [ 0, %9 ]
ret i32 %19
}