#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 {
  int /*<<< orphan*/ st_ino;
  int /*<<< orphan*/ st_dev;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int fstat(int, struct stat *);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int main() {
  struct stat orig_st;
  struct stat new_st;
  char *file_name;
  int fd = open("1.txt", O_RDONLY);
  if (fd == -1) {
    printf("%s\n", "Could not open file\n");
  }
  if (fstat(fd, &orig_st) == -1) {
    printf("%s\n", "Fstat didn't complete successfully\n");
  } else {
    printf("Original Inode is %zu\n", orig_st.st_ino);
    printf("Original Device is %zu\n", orig_st.st_dev);
  }
  close(fd);
  fd = -1;
  printf("Now sleeping for a while\n");
  sleep(10);
  fd = open("1.txt", O_RDONLY);
  if (fd == -1) {
    printf("%s\n", "Could not open file\n");
  }
  if (fstat(fd, &new_st) == -1) {
    printf("%s\n", "Fstat didn't complete successfully\n");
  } else {
    printf("Current Inode is %zu\n", new_st.st_ino);
    printf("Current Device is %zu\n", new_st.st_dev);
  }
  if ((orig_st.st_dev != new_st.st_dev) || (orig_st.st_ino != new_st.st_ino)) {
    printf("%s\n", "The file 1.txt has been modified\n");
    exit(0);
  }
  char *buffer;
  int result;
  buffer = malloc(20);
  if (buffer != NULL) {
    result = read(fd, buffer, 100);
    printf("Result is %s\n", buffer);
  } else {
    printf("malloc failed\n");
  }
  free(buffer);
  close(fd);
  fd = -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe51(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11d6 <main+0x46>
lea    0xf19(%rip),%rdi
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   10b0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1205 <main+0x75>
lea    0xeef(%rip),%rdi
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1227 <main+0x97>
mov    -0x10(%rbp),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x24(%rbp)
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   10a0 <sleep@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%esi
lea    0xda2(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1285 <main+0xf5>
lea    0xe6a(%rip),%rdi
lea    0xd88(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10b0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    12b4 <main+0x124>
lea    0xe40(%rip),%rdi
lea    0xd73(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d6 <main+0x146>
mov    -0x18(%rbp),%esi
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    12ee <main+0x15e>
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     130a <main+0x17a>
lea    0xdec(%rip),%rdi
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x14,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     134e <main+0x1be>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    $0x64,%edx
call   1060 <read@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    135c <main+0x1cc>
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x24(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2e3b(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0xe49(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11cf <main+0x2f>
lea    0xe3c(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
call   10c0 <fstat@plt>
cmp    $0xffffffff,%eax
je     1206 <main+0x66>
mov    0x10(%rsp),%esi
lea    0xe54(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rsp),%esi
lea    0xe59(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1212 <main+0x72>
lea    0xe0e(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xeab(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   10b0 <sleep@plt>
mov    0x0(%rbp),%esi
lea    0xdc7(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1251 <main+0xb1>
lea    0xdba(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
call   10c0 <fstat@plt>
cmp    $0xffffffff,%eax
je     1290 <main+0xf0>
mov    0x8(%rsp),%esi
lea    0xe01(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%ebx
lea    0xe05(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %ebx,0x14(%rsp)
je     12a6 <main+0x106>
jmp    1308 <main+0x168>
lea    0xd84(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%ebx
cmp    %ebx,0x14(%rsp)
jne    1308 <main+0x168>
mov    0x10(%rsp),%eax
cmp    0x8(%rsp),%eax
jne    1308 <main+0x168>
mov    $0x14,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12e4 <main+0x144>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
lea    0xde5(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12f0 <main+0x150>
lea    0xdf9(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xd8c(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@.str = [6 x i8] c"1.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [21 x i8] c"Could not open file\0A\00"
@.str.3 = [36 x i8] c"Fstat didn't complete successfully\0A\00"
@.str.4 = [23 x i8] c"Original Inode is %zu\0A\00"
@.str.5 = [24 x i8] c"Original Device is %zu\0A\00"
@.str.6 = [26 x i8] c"Now sleeping for a while\0A\00"
@.str.7 = [22 x i8] c"Current Inode is %zu\0A\00"
@.str.8 = [23 x i8] c"Current Device is %zu\0A\00"
@.str.9 = [34 x i8] c"The file 1.txt has been modified\0A\00"
@.str.10 = [14 x i8] c"Result is %s\0A\00"
@.str.11 = [15 x i8] c"malloc failed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = alloca %struct.stat
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %1
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %0
%15 = load i32, i32* %5
%16 = call i32 @fstat(i32 %15, %struct.stat* %2)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %27
20: ; preds = %14
%21 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 1
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %20, %18
%28 = load i32, i32* %5
%29 = call i32 @close(i32 %28)
store i32 -1, i32* %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%31 = call i32 @sleep(i32 10)
%32 = load i32, i32* @O_RDONLY
%33 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %32)
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %27
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %27
%39 = load i32, i32* %5
%40 = call i32 @fstat(i32 %39, %struct.stat* %3)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %51
44: ; preds = %38
%45 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %46)
%48 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%49 = load i32, i32* %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %44, %42
%52 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 1
%53 = load i32, i32* %52
%54 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%55 = load i32, i32* %54
%56 = icmp ne i32 %53, %55
br i1 %56, label %63, label %57
57: ; preds = %51
%58 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%59 = load i32, i32* %58
%60 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%61 = load i32, i32* %60
%62 = icmp ne i32 %59, %61
br i1 %62, label %63, label %66
63: ; preds = %57, %51
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0))
%65 = call i32 @exit(i32 0)
unreachable
66: ; preds = %57
%67 = call i8* @malloc(i32 20)
store i8* %67, i8** %6
%68 = load i8*, i8** %6
%69 = icmp ne i8* %68, null
br i1 %69, label %70, label %76
70: ; preds = %66
%71 = load i32, i32* %5
%72 = load i8*, i8** %6
%73 = call i32 @read(i32 %71, i8* %72, i32 100)
store i32 %73, i32* %7
%74 = load i8*, i8** %6
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %74)
br label %78
76: ; preds = %66
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %78
78: ; preds = %76, %70
%79 = load i8*, i8** %6
%80 = call i32 @free(i8* %79)
%81 = load i32, i32* %5
%82 = call i32 @close(i32 %81)
store i32 -1, i32* %5
%83 = load i32, i32* %1
ret i32 %83
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@.str = [6 x i8] c"1.txt\00"
@O_RDONLY = global i32 0
@.str.2 = [21 x i8] c"Could not open file\0A\00"
@.str.3 = [36 x i8] c"Fstat didn't complete successfully\0A\00"
@.str.4 = [23 x i8] c"Original Inode is %zu\0A\00"
@.str.5 = [24 x i8] c"Original Device is %zu\0A\00"
@.str.7 = [22 x i8] c"Current Inode is %zu\0A\00"
@.str.8 = [23 x i8] c"Current Device is %zu\0A\00"
@.str.9 = [34 x i8] c"The file 1.txt has been modified\0A\00"
@.str.10 = [14 x i8] c"Result is %s\0A\00"
@str = [25 x i8] c"Now sleeping for a while\00"
@str.12 = [14 x i8] c"malloc failed\00"
define i32 @main() {
%1 = alloca %struct.stat
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %1 to i8*
%4 = bitcast %struct.stat* %2 to i8*
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = call i32 @fstat(i32 %6, %struct.stat* %1)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %22
15: ; preds = %10
%16 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%17 = load i32, i32* %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%20 = load i32, i32* %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %15, %13
%23 = tail call i32 @close(i32 %6)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%25 = tail call i32 @sleep(i32 10)
%26 = load i32, i32* @O_RDONLY
%27 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %22
%32 = call i32 @fstat(i32 %27, %struct.stat* %2)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%36 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%37 = load i32, i32* %36
br label %45
38: ; preds = %31
%39 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%40 = load i32, i32* %39
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%43 = load i32, i32* %42
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %38, %34
%46 = phi i32 [ %43, %38 ], [ %37, %34 ]
%47 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%48 = load i32, i32* %47
%49 = icmp eq i32 %48, %46
br i1 %49, label %50, label %56
50: ; preds = %45
%51 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%52 = load i32, i32* %51
%53 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%54 = load i32, i32* %53
%55 = icmp eq i32 %52, %54
br i1 %55, label %59, label %56
56: ; preds = %50, %45
%57 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0))
%58 = tail call i32 @exit(i32 0)
unreachable
59: ; preds = %50
%60 = tail call dereferenceable_or_null(20) i8* @malloc(i32 20)
%61 = icmp eq i8* %60, null
br i1 %61, label %65, label %62
62: ; preds = %59
%63 = tail call i32 @read(i32 %27, i8* %60, i32 100)
%64 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %60)
br label %67
65: ; preds = %59
%66 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.12, i64 0, i64 0))
br label %67
67: ; preds = %65, %62
%68 = tail call i32 @free(i8* %60)
%69 = tail call i32 @close(i32 %27)
ret i32 0
}