#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_ino;
  scalar_t__ st_dev;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fstat(int, struct stat *);
int open(char *, int /*<<< orphan*/);
int same_file(char *src, char *dst) {
  struct stat s1;
  struct stat s2;
  int f1;
  int f2;
  f1 = open(src, O_RDONLY);
  f2 = open(dst, O_RDONLY);
  fstat(f1, &s1);
  fstat(f2, &s2);
  close(f1);
  close(f2);
  return s1.st_ino == s2.st_ino && s1.st_dev == s2.st_dev;
}


x86 assembly (clang, -O0):
<same_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1050 <fstat@plt>
mov    -0x38(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1050 <fstat@plt>
mov    -0x34(%rbp),%edi
call   1030 <close@plt>
mov    -0x38(%rbp),%edi
call   1030 <close@plt>
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x30(%rbp),%rcx
mov    %al,-0x39(%rbp)
jne    11b3 <same_file+0x83>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
sete   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<same_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    0x2ea6(%rip),%r14
mov    (%r14),%esi
call   1040 <open@plt>
mov    %eax,%ebp
mov    (%r14),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
call   1050 <fstat@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
call   1050 <fstat@plt>
mov    %ebp,%edi
call   1030 <close@plt>
mov    %ebx,%edi
call   1030 <close@plt>
mov    0x10(%rsp),%rcx
mov    0x18(%rsp),%rdx
xor    (%rsp),%rcx
xor    0x8(%rsp),%rdx
xor    %eax,%eax
or     %rcx,%rdx
sete   %al
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
@O_RDONLY = global i32 0
define i32 @same_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.stat
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %7
%12 = load i8*, i8** %4
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %8
%15 = load i32, i32* %7
%16 = call i32 @fstat(i32 %15, %struct.stat* %5)
%17 = load i32, i32* %8
%18 = call i32 @fstat(i32 %17, %struct.stat* %6)
%19 = load i32, i32* %7
%20 = call i32 @close(i32 %19)
%21 = load i32, i32* %8
%22 = call i32 @close(i32 %21)
%23 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%24 = load i64, i64* %23
%25 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%26 = load i64, i64* %25
%27 = icmp eq i64 %24, %26
br i1 %27, label %28, label %34
28: ; preds = %2
%29 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 1
%30 = load i64, i64* %29
%31 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%32 = load i64, i64* %31
%33 = icmp eq i64 %30, %32
br label %34
34: ; preds = %28, %2
%35 = phi i1 [ false, %2 ], [ %33, %28 ]
%36 = zext i1 %35 to i32
ret i32 %36
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
@O_RDONLY = global i32 0
define i32 @same_file(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %0, i32 %7)
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* %1, i32 %9)
%11 = call i32 @fstat(i32 %8, %struct.stat* %3)
%12 = call i32 @fstat(i32 %10, %struct.stat* %4)
%13 = tail call i32 @close(i32 %8)
%14 = tail call i32 @close(i32 %10)
%15 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%16 = load i64, i64* %15
%17 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%18 = load i64, i64* %17
%19 = icmp eq i64 %16, %18
%20 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%21 = load i64, i64* %20
%22 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%23 = load i64, i64* %22
%24 = icmp eq i64 %21, %23
%25 = select i1 %19, i1 %24, i1 false
%26 = zext i1 %25 to i32
ret i32 %26
}