#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*/ die(int, char *, char *);
scalar_t__ stat(char *, struct stat *);
bool is_same_file(char *filea, char *fileb) {
  struct stat a, b;
  if (stat(filea, &a) < 0)
    die(30, "stating file a: '%s'\n", filea);
  if (stat(fileb, &b) < 0)
    die(31, "stating file b: '%s'\n", fileb);
  return (a.st_dev == b.st_dev && a.st_ino == b.st_ino);
}


x86 assembly (clang, -O0):
<is_same_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
jge    115c <is_same_file+0x3c>
mov    -0x8(%rbp),%rdx
mov    $0x1e,%edi
lea    0xea9(%rip),%rsi
call   1040 <die@plt>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
jge    1188 <is_same_file+0x68>
mov    -0x10(%rbp),%rdx
mov    $0x1f,%edi
lea    0xe93(%rip),%rsi
call   1040 <die@plt>
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x30(%rbp),%rcx
mov    %al,-0x31(%rbp)
jne    11a9 <is_same_file+0x89>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_same_file>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x18(%rsp),%rsi
call   1030 <stat@plt>
test   %rax,%rax
jns    1150 <is_same_file+0x30>
lea    0xebd(%rip),%rsi
mov    $0x1e,%edi
mov    %rbx,%rdx
call   1040 <die@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1030 <stat@plt>
test   %rax,%rax
jns    1176 <is_same_file+0x56>
lea    0xead(%rip),%rsi
mov    $0x1f,%edi
mov    %r14,%rdx
call   1040 <die@plt>
mov    0x18(%rsp),%rcx
mov    0x20(%rsp),%rdx
xor    0x8(%rsp),%rcx
xor    0x10(%rsp),%rdx
xor    %eax,%eax
or     %rcx,%rdx
sete   %al
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
@.str = [22 x i8] c"stating file a: '%s'\0A\00"
@.str.1 = [22 x i8] c"stating file b: '%s'\0A\00"
define i32 @is_same_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.stat
%6 = alloca %struct.stat
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i64 @stat(i8* %7, %struct.stat* %5)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 @die(i32 30, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %10, %2
%14 = load i8*, i8** %4
%15 = call i64 @stat(i8* %14, %struct.stat* %6)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = call i32 @die(i32 31, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %13
%21 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%22 = load i64, i64* %21
%23 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%24 = load i64, i64* %23
%25 = icmp eq i64 %22, %24
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 1
%28 = load i64, i64* %27
%29 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%30 = load i64, i64* %29
%31 = icmp eq i64 %28, %30
br label %32
32: ; preds = %26, %20
%33 = phi i1 [ false, %20 ], [ %31, %26 ]
%34 = zext i1 %33 to i32
ret i32 %34
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
@.str = [22 x i8] c"stating file a: '%s'\0A\00"
@.str.1 = [22 x i8] c"stating file b: '%s'\0A\00"
define i32 @is_same_file(i8* %0, i8* %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 i64 @stat(i8* %0, %struct.stat* %3)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @die(i32 30, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %11
11: ; preds = %9, %2
%12 = call i64 @stat(i8* %1, %struct.stat* %4)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @die(i32 31, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %16
16: ; preds = %14, %11
%17 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%18 = load i64, i64* %17
%19 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%20 = load i64, i64* %19
%21 = icmp eq i64 %18, %20
%22 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%23 = load i64, i64* %22
%24 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%25 = load i64, i64* %24
%26 = icmp eq i64 %23, %25
%27 = select i1 %21, i1 %26, i1 false
%28 = zext i1 %27 to i32
ret i32 %28
}