#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 */
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ strcmp(char const *, char const *);
bool files_are_same(const char *filea, const char *fileb) {
  struct stat a, b;
  if (!strcmp(filea, fileb))
    return true;
  if (stat(filea, &a) < 0)
    return false;
  if (stat(fileb, &b) < 0)
    return false;
  return a.st_dev == b.st_dev && a.st_ino == b.st_ino;
}


x86 assembly (clang, -O0):
<files_are_same>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1152 <files_are_same+0x32>
movl   $0x1,-0x4(%rbp)
jmp    11c4 <files_are_same+0xa4>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    1175 <files_are_same+0x55>
movl   $0x0,-0x4(%rbp)
jmp    11c4 <files_are_same+0xa4>
mov    -0x18(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    1198 <files_are_same+0x78>
movl   $0x0,-0x4(%rbp)
jmp    11c4 <files_are_same+0xa4>
mov    -0x28(%rbp),%rcx
xor    %eax,%eax
cmp    -0x38(%rbp),%rcx
mov    %al,-0x39(%rbp)
jne    11b9 <files_are_same+0x99>
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
sete   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<files_are_same>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strcmp@plt>
test   %eax,%eax
je     117a <files_are_same+0x5a>
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
xor    %ebx,%ebx
test   %rax,%rax
js     117f <files_are_same+0x5f>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1040 <stat@plt>
test   %rax,%rax
js     117f <files_are_same+0x5f>
mov    0x18(%rsp),%rax
mov    0x20(%rsp),%rcx
xor    0x8(%rsp),%rax
xor    0x10(%rsp),%rcx
xor    %ebx,%ebx
or     %rax,%rcx
sete   %bl
jmp    117f <files_are_same+0x5f>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
define i32 @files_are_same(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.stat
%7 = alloca %struct.stat
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = call i32 @strcmp(i8* %8, i8* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 1, i32* %3
br label %38
13: ; preds = %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 %18
17: ; preds = %13
store i32 0, i32* %3
br label %38
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = call i64 @stat(i8* %19, %struct.stat* %7)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 0, i32* %3
br label %38
23: ; preds = %18
%24 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%25 = load i64, i64* %24
%26 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%27 = load i64, i64* %26
%28 = icmp eq i64 %25, %27
br i1 %28, label %29, label %35
29: ; preds = %23
%30 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%31 = load i64, i64* %30
%32 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%33 = load i64, i64* %32
%34 = icmp eq i64 %31, %33
br label %35
35: ; preds = %29, %23
%36 = phi i1 [ false, %23 ], [ %34, %29 ]
%37 = zext i1 %36 to i32
store i32 %37, i32* %3
br label %38
38: ; preds = %35, %22, %17, %12
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
define i32 @files_are_same(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 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %28, label %9
9: ; preds = %2
%10 = call i64 @stat(i8* %0, %struct.stat* %3)
%11 = icmp slt i64 %10, 0
br i1 %11, label %28, label %12
12: ; preds = %9
%13 = call i64 @stat(i8* %1, %struct.stat* %4)
%14 = icmp slt i64 %13, 0
br i1 %14, label %28, label %15
15: ; preds = %12
%16 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%17 = load i64, i64* %16
%18 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%19 = load i64, i64* %18
%20 = icmp eq i64 %17, %19
%21 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%22 = load i64, i64* %21
%23 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%24 = load i64, i64* %23
%25 = icmp eq i64 %22, %24
%26 = select i1 %20, i1 %25, i1 false
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %12, %9, %2, %15
%29 = phi i32 [ %27, %15 ], [ 1, %2 ], [ 0, %9 ], [ 0, %12 ]
ret i32 %29
}