#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 */
scalar_t__ stat(char *, struct stat *);
scalar_t__ strcmp(char *, char *);
char *strrchr(char *, char);
int mg_same_file(char *fname1, char *fname2) {
  struct stat st1, st2;
  char *tail1, *tail2;
  if ((fname1 != NULL) != (fname2 != NULL))
    return 0;
  if (fname1 == NULL || strcmp(fname1, fname2) == 0)
    return 1;
  tail1 = strrchr(fname1, '/');
  if (tail1 == NULL)
    tail1 = fname1;
  tail2 = strrchr(fname2, '/');
  if (tail2 == NULL)
    tail2 = fname2;
  if (strcmp(fname1, fname2) != 0)
    return 0;
  if (stat(fname1, &st1) < 0 || stat(fname2, &st2) < 0 ||
      st1.st_ino != st2.st_ino || st1.st_dev != st2.st_dev)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<mg_same_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
cmpq   $0x0,-0x18(%rbp)
setne  %cl
and    $0x1,%cl
movzbl %cl,%ecx
cmp    %ecx,%eax
je     116f <mg_same_file+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    1267 <mg_same_file+0x137>
cmpq   $0x0,-0x10(%rbp)
je     1191 <mg_same_file+0x61>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    119d <mg_same_file+0x6d>
movl   $0x1,-0x4(%rbp)
jmp    1267 <mg_same_file+0x137>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11c2 <mg_same_file+0x92>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11e7 <mg_same_file+0xb7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     120a <mg_same_file+0xda>
movl   $0x0,-0x4(%rbp)
jmp    1267 <mg_same_file+0x137>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jl     1254 <mg_same_file+0x124>
mov    -0x18(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jl     1254 <mg_same_file+0x124>
mov    -0x28(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    1254 <mg_same_file+0x124>
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     1260 <mg_same_file+0x130>
movl   $0x0,-0x4(%rbp)
jmp    1267 <mg_same_file+0x137>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mg_same_file>:
push   %r14
push   %rbx
sub    $0x28,%rsp
test   %rdi,%rdi
sete   %cl
test   %rsi,%rsi
sete   %al
xor    %cl,%al
xor    $0x1,%al
test   %rdi,%rdi
je     116a <mg_same_file+0x4a>
mov    %rsi,%r14
test   %rsi,%rsi
je     116a <mg_same_file+0x4a>
mov    %rdi,%rbx
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1168 <mg_same_file+0x48>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1175 <mg_same_file+0x55>
xor    %eax,%eax
jmp    116a <mg_same_file+0x4a>
mov    $0x1,%al
movzbl %al,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
test   %rax,%rax
js     1164 <mg_same_file+0x44>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1040 <stat@plt>
test   %rax,%rax
js     1164 <mg_same_file+0x44>
mov    0x18(%rsp),%rax
cmp    0x8(%rsp),%rax
jne    1164 <mg_same_file+0x44>
mov    0x20(%rsp),%rax
cmp    0x10(%rsp),%rax
sete   %al
jmp    116a <mg_same_file+0x4a>

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
define i32 @mg_same_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.stat
%7 = alloca %struct.stat
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
%12 = zext i1 %11 to i32
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
%15 = zext i1 %14 to i32
%16 = icmp ne i32 %12, %15
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 0, i32* %3
br label %69
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = icmp eq i8* %19, null
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = load i8*, i8** %4
%23 = load i8*, i8** %5
%24 = call i64 @strcmp(i8* %22, i8* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21, %18
store i32 1, i32* %3
br label %69
27: ; preds = %21
%28 = load i8*, i8** %4
%29 = call i8* @strrchr(i8* %28, i8 signext 47)
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = load i8*, i8** %4
store i8* %33, i8** %8
br label %34
34: ; preds = %32, %27
%35 = load i8*, i8** %5
%36 = call i8* @strrchr(i8* %35, i8 signext 47)
store i8* %36, i8** %9
%37 = load i8*, i8** %9
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = load i8*, i8** %5
store i8* %40, i8** %9
br label %41
41: ; preds = %39, %34
%42 = load i8*, i8** %4
%43 = load i8*, i8** %5
%44 = call i64 @strcmp(i8* %42, i8* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %41
store i32 0, i32* %3
br label %69
47: ; preds = %41
%48 = load i8*, i8** %4
%49 = call i64 @stat(i8* %48, %struct.stat* %6)
%50 = icmp slt i64 %49, 0
br i1 %50, label %67, label %51
51: ; preds = %47
%52 = load i8*, i8** %5
%53 = call i64 @stat(i8* %52, %struct.stat* %7)
%54 = icmp slt i64 %53, 0
br i1 %54, label %67, label %55
55: ; preds = %51
%56 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%57 = load i64, i64* %56
%58 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%59 = load i64, i64* %58
%60 = icmp ne i64 %57, %59
br i1 %60, label %67, label %61
61: ; preds = %55
%62 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%63 = load i64, i64* %62
%64 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%65 = load i64, i64* %64
%66 = icmp ne i64 %63, %65
br i1 %66, label %67, label %68
67: ; preds = %61, %55, %51, %47
store i32 0, i32* %3
br label %69
68: ; preds = %61
store i32 1, i32* %3
br label %69
69: ; preds = %68, %67, %46, %26, %17
%70 = load i32, i32* %3
ret i32 %70
}

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