#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_dev;
  scalar_t__ st_ino;
};

/* Variables and functions */
int /*<<< orphan*/ fstat(int, struct stat *);
int same_file_behind_fds_posix(int fd1, int fd2) {
  struct stat fd1_stat, fd2_stat;
  fstat(fd1, &fd1_stat);
  fstat(fd2, &fd2_stat);
  return (fd1_stat.st_dev == fd2_stat.st_dev &&
          fd1_stat.st_ino == fd2_stat.st_ino)
             ? 0
             : 1;
}


x86 assembly (clang, -O0):
<same_file_behind_fds_posix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1030 <fstat@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1030 <fstat@plt>
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x28(%rbp),%rcx
mov    %al,-0x29(%rbp)
jne    1157 <same_file_behind_fds_posix+0x47>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%dl
mov    $0x1,%eax
xor    %ecx,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<same_file_behind_fds_posix>:
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebx
lea    0x10(%rsp),%rsi
call   1030 <fstat@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
call   1030 <fstat@plt>
mov    0x10(%rsp),%rcx
mov    0x18(%rsp),%rdx
xor    (%rsp),%rcx
xor    0x8(%rsp),%rdx
xor    %eax,%eax
or     %rcx,%rdx
setne  %al
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
define i32 @same_file_behind_fds_posix(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.stat
%6 = alloca %struct.stat
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = call i32 @fstat(i32 %7, %struct.stat* %5)
%9 = load i32, i32* %4
%10 = call i32 @fstat(i32 %9, %struct.stat* %6)
%11 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%12 = load i64, i64* %11
%13 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%14 = load i64, i64* %13
%15 = icmp eq i64 %12, %14
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 1
%18 = load i64, i64* %17
%19 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%20 = load i64, i64* %19
%21 = icmp eq i64 %18, %20
br label %22
22: ; preds = %16, %2
%23 = phi i1 [ false, %2 ], [ %21, %16 ]
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 0, i32 1
ret i32 %25
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
define i32 @same_file_behind_fds_posix(i32 %0, i32 %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = call i32 @fstat(i32 %0, %struct.stat* %3)
%8 = call i32 @fstat(i32 %1, %struct.stat* %4)
%9 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%12 = load i64, i64* %11
%13 = icmp ne i64 %10, %12
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%15 = load i64, i64* %14
%16 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%17 = load i64, i64* %16
%18 = icmp ne i64 %15, %17
%19 = select i1 %13, i1 true, i1 %18
%20 = zext i1 %19 to i32
ret i32 %20
}