#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;
};

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fatal(int /*<<< orphan*/, char *, char const *,
                         int /*<<< orphan*/);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
extern int samefs(const char *src, const char *dst) {
  struct stat s;
  struct stat d;
  if (stat(src, &s))
    fatal(0, "in samefs(): stat(\"%s\") failed: %s", src, strerror(errno));
  if (stat(dst, &d))
    fatal(0, "in samefs(): stat(\"%s\") failed: %s", dst, strerror(errno));
  return s.st_dev == d.st_dev;
}


x86 assembly (clang, -O0):
<samefs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
je     1181 <samefs+0x51>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    -0x28(%rbp),%rdx
mov    %eax,%ecx
xor    %edi,%edi
lea    0xe84(%rip),%rsi
call   1050 <fatal@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
je     11c2 <samefs+0x92>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
xor    %edi,%edi
lea    0xe43(%rip),%rsi
call   1050 <fatal@plt>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<samefs>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x10(%rsp),%rsi
call   1030 <stat@plt>
test   %rax,%rax
je     116d <samefs+0x3d>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
lea    0xe9f(%rip),%rsi
xor    %edi,%edi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1050 <fatal@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1030 <stat@plt>
test   %rax,%rax
je     11a0 <samefs+0x70>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
lea    0xe6c(%rip),%rsi
xor    %edi,%edi
mov    %r14,%rdx
mov    %eax,%ecx
call   1050 <fatal@plt>
mov    0x10(%rsp),%rcx
xor    %eax,%eax
cmp    0x8(%rsp),%rcx
sete   %al
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [35 x i8] c"in samefs(): stat(\22%s\22) failed: %s\00"
@errno = global i32 0
define i32 @samefs(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 ne i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = call i32 @fatal(i32 0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %13)
br label %15
15: ; preds = %10, %2
%16 = load i8*, i8** %4
%17 = call i64 @stat(i8* %16, %struct.stat* %6)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = load i32, i32* @errno
%22 = call i32 @strerror(i32 %21)
%23 = call i32 @fatal(i32 0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %20, i32 %22)
br label %24
24: ; preds = %19, %15
%25 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%26 = load i64, i64* %25
%27 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%28 = load i64, i64* %27
%29 = icmp eq i64 %26, %28
%30 = zext i1 %29 to i32
ret i32 %30
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [35 x i8] c"in samefs(): stat(\22%s\22) failed: %s\00"
@errno = global i32 0
define i32 @samefs(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 eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @errno
%11 = call i32 @strerror(i32 %10)
%12 = call i32 @fatal(i32 0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %11)
br label %13
13: ; preds = %9, %2
%14 = call i64 @stat(i8* %1, %struct.stat* %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @fatal(i32 0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %18)
br label %20
20: ; preds = %16, %13
%21 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%22 = load i64, i64* %21
%23 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%24 = load i64, i64* %23
%25 = icmp eq i64 %22, %24
%26 = zext i1 %25 to i32
ret i32 %26
}