#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_rdev;
  scalar_t__ st_dev;
  scalar_t__ st_ino;
  int /*<<< orphan*/ st_mode;
};
typedef int /*<<< orphan*/ real_b;
typedef int /*<<< orphan*/ real_a;

/* Variables and functions */
int ENOENT;
int PATH_MAX;
scalar_t__ S_ISBLK(int /*<<< orphan*/);
int /*<<< orphan*/ __strncpy_null(char *, char const *, int);
int errno;
int /*<<< orphan*/ realpath(char const *, char *);
scalar_t__ stat(char const *, struct stat *);
scalar_t__ strcmp(char *, char *);
int is_same_blk_file(const char *a, const char *b) {
  struct stat st_buf_a, st_buf_b;
  char real_a[PATH_MAX];
  char real_b[PATH_MAX];
  if (!realpath(a, real_a))
    __strncpy_null(real_a, a, sizeof(real_a));
  if (!realpath(b, real_b))
    __strncpy_null(real_b, b, sizeof(real_b));
  if (strcmp(real_a, real_b) == 0)
    return 1;
  if (stat(a, &st_buf_a) < 0 || stat(b, &st_buf_b) < 0) {
    if (errno == ENOENT)
      return 0;
    return -errno;
  }
  if (S_ISBLK(st_buf_a.st_mode) && S_ISBLK(st_buf_b.st_mode) &&
      st_buf_a.st_rdev == st_buf_b.st_rdev) {
    return 1;
  }
  if (st_buf_a.st_dev == st_buf_b.st_dev &&
      st_buf_a.st_ino == st_buf_b.st_ino) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<is_same_blk_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%ecx
mov    %rcx,-0x98(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x60(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rsi
sub    %rdx,%rsi
mov    %rsi,-0x90(%rbp)
mov    %rsi,%rsp
mov    %rcx,-0x68(%rbp)
mov    (%rax),%eax
mov    %rax,-0x88(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <realpath@plt>
cmp    $0x0,%eax
jne    11e9 <is_same_blk_file+0x99>
mov    -0x90(%rbp),%rdi
mov    -0x98(%rbp),%rax
mov    -0x10(%rbp),%rsi
mov    %eax,%edx
call   1030 <__strncpy_null@plt>
mov    -0x80(%rbp),%rsi
mov    -0x18(%rbp),%rdi
call   1060 <realpath@plt>
cmp    $0x0,%eax
jne    1215 <is_same_blk_file+0xc5>
mov    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%rax
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
call   1030 <__strncpy_null@plt>
mov    -0x80(%rbp),%rsi
mov    -0x90(%rbp),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1242 <is_same_blk_file+0xf2>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x74(%rbp)
jmp    1337 <is_same_blk_file+0x1e7>
mov    -0x10(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jl     1270 <is_same_blk_file+0x120>
mov    -0x18(%rbp),%rdi
lea    -0x58(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    12b5 <is_same_blk_file+0x165>
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
mov    0x2d48(%rip),%rcx
cmp    (%rcx),%eax
jne    129b <is_same_blk_file+0x14b>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x74(%rbp)
jmp    1337 <is_same_blk_file+0x1e7>
xor    %eax,%eax
mov    0x2d34(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x74(%rbp)
jmp    1337 <is_same_blk_file+0x1e7>
mov    -0x20(%rbp),%edi
call   1070 <S_ISBLK@plt>
cmp    $0x0,%rax
je     12fa <is_same_blk_file+0x1aa>
mov    -0x40(%rbp),%edi
call   1070 <S_ISBLK@plt>
cmp    $0x0,%rax
je     12fa <is_same_blk_file+0x1aa>
mov    -0x38(%rbp),%rax
cmp    -0x58(%rbp),%rax
jne    12fa <is_same_blk_file+0x1aa>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x74(%rbp)
jmp    1337 <is_same_blk_file+0x1e7>
mov    -0x30(%rbp),%rax
cmp    -0x50(%rbp),%rax
jne    1329 <is_same_blk_file+0x1d9>
mov    -0x28(%rbp),%rax
cmp    -0x48(%rbp),%rax
jne    1329 <is_same_blk_file+0x1d9>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x74(%rbp)
jmp    1337 <is_same_blk_file+0x1e7>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x74(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_same_blk_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r15
mov    %rsp,-0x30(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r12
lea    0xf(%r14),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r12
mov    %r12,%rsp
mov    (%rax),%r13d
mov    %rsp,%rbx
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rdi,-0x38(%rbp)
mov    %r12,%rsi
call   1060 <realpath@plt>
test   %eax,%eax
jne    11b6 <is_same_blk_file+0x66>
mov    %r12,%rdi
mov    -0x38(%rbp),%rsi
mov    %r14d,%edx
call   1030 <__strncpy_null@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <realpath@plt>
test   %eax,%eax
jne    11d3 <is_same_blk_file+0x83>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1030 <__strncpy_null@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     1266 <is_same_blk_file+0x116>
lea    -0x78(%rbp),%rsi
mov    -0x38(%rbp),%rdi
call   1050 <stat@plt>
test   %rax,%rax
js     124b <is_same_blk_file+0xfb>
lea    -0x58(%rbp),%rsi
mov    %r15,%rdi
call   1050 <stat@plt>
test   %rax,%rax
js     124b <is_same_blk_file+0xfb>
mov    -0x60(%rbp),%edi
call   1070 <S_ISBLK@plt>
test   %rax,%rax
je     122f <is_same_blk_file+0xdf>
mov    -0x40(%rbp),%edi
call   1070 <S_ISBLK@plt>
test   %rax,%rax
je     122f <is_same_blk_file+0xdf>
mov    -0x78(%rbp),%rax
cmp    -0x58(%rbp),%rax
je     1266 <is_same_blk_file+0x116>
mov    -0x70(%rbp),%rax
cmp    -0x50(%rbp),%rax
mov    -0x30(%rbp),%rcx
jne    1247 <is_same_blk_file+0xf7>
mov    -0x68(%rbp),%rax
cmp    -0x48(%rbp),%rax
je     126a <is_same_blk_file+0x11a>
xor    %ebx,%ebx
jmp    126a <is_same_blk_file+0x11a>
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    0x2d6d(%rip),%rcx
mov    %eax,%edx
neg    %edx
xor    %ebx,%ebx
cmp    (%rcx),%eax
cmovne %edx,%ebx
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsp
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64, i64, i64, i32 }
@PATH_MAX = global i32 0
@errno = global i32 0
@ENOENT = global i32 0
define i32 @is_same_blk_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 i64
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%12 = load i32, i32* @PATH_MAX
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i8, i64 %13
store i64 %13, i64* %9
%16 = load i32, i32* @PATH_MAX
%17 = zext i32 %16 to i64
%18 = alloca i8, i64 %17
store i64 %17, i64* %10
%19 = load i8*, i8** %4
%20 = call i32 @realpath(i8* %19, i8* %15)
%21 = icmp ne i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %2
%23 = load i8*, i8** %4
%24 = trunc i64 %13 to i32
%25 = call i32 @__strncpy_null(i8* %15, i8* %23, i32 %24)
br label %26
26: ; preds = %22, %2
%27 = load i8*, i8** %5
%28 = call i32 @realpath(i8* %27, i8* %18)
%29 = icmp ne i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = load i8*, i8** %5
%32 = trunc i64 %17 to i32
%33 = call i32 @__strncpy_null(i8* %18, i8* %31, i32 %32)
br label %34
34: ; preds = %30, %26
%35 = call i64 @strcmp(i8* %15, i8* %18)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 1, i32* %3
store i32 1, i32* %11
br label %85
38: ; preds = %34
%39 = load i8*, i8** %4
%40 = call i64 @stat(i8* %39, %struct.stat* %6)
%41 = icmp slt i64 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %38
%43 = load i8*, i8** %5
%44 = call i64 @stat(i8* %43, %struct.stat* %7)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %42, %38
%47 = load i32, i32* @errno
%48 = load i32, i32* @ENOENT
%49 = icmp eq i32 %47, %48
br i1 %49, label %50, label %51
50: ; preds = %46
store i32 0, i32* %3
store i32 1, i32* %11
br label %85
51: ; preds = %46
%52 = load i32, i32* @errno
%53 = sub nsw i32 0, %52
store i32 %53, i32* %3
store i32 1, i32* %11
br label %85
54: ; preds = %42
%55 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 3
%56 = load i32, i32* %55
%57 = call i64 @S_ISBLK(i32 %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %71
59: ; preds = %54
%60 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 3
%61 = load i32, i32* %60
%62 = call i64 @S_ISBLK(i32 %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %71
64: ; preds = %59
%65 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%66 = load i64, i64* %65
%67 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%68 = load i64, i64* %67
%69 = icmp eq i64 %66, %68
br i1 %69, label %70, label %71
70: ; preds = %64
store i32 1, i32* %3
store i32 1, i32* %11
br label %85
71: ; preds = %64, %59, %54
%72 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%73 = load i64, i64* %72
%74 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%75 = load i64, i64* %74
%76 = icmp eq i64 %73, %75
br i1 %76, label %77, label %84
77: ; preds = %71
%78 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 2
%79 = load i64, i64* %78
%80 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 2
%81 = load i64, i64* %80
%82 = icmp eq i64 %79, %81
br i1 %82, label %83, label %84
83: ; preds = %77
store i32 1, i32* %3
store i32 1, i32* %11
br label %85
84: ; preds = %77, %71
store i32 0, i32* %3
store i32 1, i32* %11
br label %85
85: ; preds = %84, %83, %70, %51, %50, %37
%86 = load i8*, i8** %8
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
%struct.stat = type { i64, i64, i64, i32 }
@PATH_MAX = global i32 0
@errno = global i32 0
@ENOENT = global i32 0
define i32 @is_same_blk_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 = load i32, i32* @PATH_MAX
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = load i32, i32* @PATH_MAX
%12 = zext i32 %11 to i64
%13 = alloca i8, i64 %12
%14 = call i32 @realpath(i8* %0, i8* %10)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @__strncpy_null(i8* %10, i8* %0, i32 %7)
br label %18
18: ; preds = %16, %2
%19 = call i32 @realpath(i8* %1, i8* %13)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @__strncpy_null(i8* %13, i8* %1, i32 %11)
br label %23
23: ; preds = %21, %18
%24 = call i64 @strcmp(i8* %10, i8* %13)
%25 = icmp eq i64 %24, 0
br i1 %25, label %67, label %26
26: ; preds = %23
%27 = call i64 @stat(i8* %0, %struct.stat* %3)
%28 = icmp slt i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = call i64 @stat(i8* %1, %struct.stat* %4)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %29, %26
%33 = load i32, i32* @errno
%34 = load i32, i32* @ENOENT
%35 = icmp eq i32 %33, %34
%36 = sub nsw i32 0, %33
%37 = select i1 %35, i32 0, i32 %36
br label %67
38: ; preds = %29
%39 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 3
%40 = load i32, i32* %39
%41 = call i64 @S_ISBLK(i32 %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %54, label %43
43: ; preds = %38
%44 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 3
%45 = load i32, i32* %44
%46 = call i64 @S_ISBLK(i32 %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %54, label %48
48: ; preds = %43
%49 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%50 = load i64, i64* %49
%51 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%52 = load i64, i64* %51
%53 = icmp eq i64 %50, %52
br i1 %53, label %67, label %54
54: ; preds = %48, %43, %38
%55 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%56 = load i64, i64* %55
%57 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%58 = load i64, i64* %57
%59 = icmp eq i64 %56, %58
br i1 %59, label %60, label %66
60: ; preds = %54
%61 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 2
%62 = load i64, i64* %61
%63 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 2
%64 = load i64, i64* %63
%65 = icmp eq i64 %62, %64
br i1 %65, label %67, label %66
66: ; preds = %60, %54
br label %67
67: ; preds = %32, %60, %48, %23, %66
%68 = phi i32 [ 0, %66 ], [ 1, %23 ], [ 1, %48 ], [ 1, %60 ], [ %37, %32 ]
ret i32 %68
}