#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;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int O_DIRECTORY;
int O_RDONLY;
int /*<<< orphan*/ assert(int);
int fstat(int, struct stat *);
int open(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int main(void) {
  int fd0, fd1, fd2;
  struct stat st0, st1, st2;
  char buf[64];
  int rv;
  fd0 = open("/", O_DIRECTORY | O_RDONLY);
  assert(fd0 >= 0);
  snprintf(buf, sizeof(buf), "/proc/self/fd/%u", fd0);
  fd1 = open(buf, O_RDONLY);
  assert(fd1 >= 0);
  snprintf(buf, sizeof(buf), "/proc/thread-self/fd/%u", fd0);
  fd2 = open(buf, O_RDONLY);
  assert(fd2 >= 0);
  rv = fstat(fd0, &st0);
  assert(rv == 0);
  rv = fstat(fd1, &st1);
  assert(rv == 0);
  rv = fstat(fd2, &st2);
  assert(rv == 0);
  assert(st0.st_dev == st1.st_dev);
  assert(st0.st_ino == st1.st_ino);
  assert(st0.st_dev == st2.st_dev);
  assert(st0.st_ino == st2.st_ino);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
mov    0x2e86(%rip),%rax
or     (%rax),%esi
lea    0xe95(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x40,%esi
lea    0xe6b(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x40,%esi
lea    0xe3e(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1060 <fstat@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1060 <fstat@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1060 <fstat@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%rax
cmp    -0x40(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
cmp    -0x38(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    0x2e87(%rip),%rax
mov    0x2e90(%rip),%r15
mov    (%r15),%esi
or     (%rax),%esi
lea    0xe9c(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
lea    0xe84(%rip),%rdx
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %ebx,%ecx
call   1030 <snprintf@plt>
mov    (%r15),%esi
mov    %rbp,%rdi
call   1050 <open@plt>
mov    %eax,%r14d
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
lea    0xe60(%rip),%rdx
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %ebx,%ecx
call   1030 <snprintf@plt>
mov    (%r15),%esi
mov    %rbp,%rdi
call   1050 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
call   1060 <fstat@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
call   1060 <fstat@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
call   1060 <fstat@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    0x20(%rsp),%rbx
xor    %edi,%edi
cmp    0x10(%rsp),%rbx
sete   %dil
call   1040 <assert@plt>
mov    0x28(%rsp),%rbp
xor    %edi,%edi
cmp    0x18(%rsp),%rbp
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmp    (%rsp),%rbx
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmp    0x8(%rsp),%rbp
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
@.str = [2 x i8] c"/\00"
@O_DIRECTORY = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [17 x i8] c"/proc/self/fd/%u\00"
@.str.2 = [24 x i8] c"/proc/thread-self/fd/%u\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.stat
%6 = alloca %struct.stat
%7 = alloca %struct.stat
%8 = alloca [64 x i8]
%9 = alloca i32
store i32 0, i32* %1
%10 = load i32, i32* @O_DIRECTORY
%11 = load i32, i32* @O_RDONLY
%12 = or i32 %10, %11
%13 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = icmp sge i32 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%19 = load i32, i32* %2
%20 = call i32 @snprintf(i8* %18, i32 64, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp sge i32 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%29 = load i32, i32* %2
%30 = call i32 @snprintf(i8* %28, i32 64, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%32 = load i32, i32* @O_RDONLY
%33 = call i32 @open(i8* %31, i32 %32)
store i32 %33, i32* %4
%34 = load i32, i32* %4
%35 = icmp sge i32 %34, 0
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i32, i32* %2
%39 = call i32 @fstat(i32 %38, %struct.stat* %5)
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = icmp eq i32 %40, 0
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i32, i32* %3
%45 = call i32 @fstat(i32 %44, %struct.stat* %6)
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = icmp eq i32 %46, 0
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load i32, i32* %4
%51 = call i32 @fstat(i32 %50, %struct.stat* %7)
store i32 %51, i32* %9
%52 = load i32, i32* %9
%53 = icmp eq i32 %52, 0
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
%56 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%57 = load i64, i64* %56
%58 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%59 = load i64, i64* %58
%60 = icmp eq i64 %57, %59
%61 = zext i1 %60 to i32
%62 = call i32 @assert(i32 %61)
%63 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 1
%64 = load i64, i64* %63
%65 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%66 = load i64, i64* %65
%67 = icmp eq i64 %64, %66
%68 = zext i1 %67 to i32
%69 = call i32 @assert(i32 %68)
%70 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%71 = load i64, i64* %70
%72 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%73 = load i64, i64* %72
%74 = icmp eq i64 %71, %73
%75 = zext i1 %74 to i32
%76 = call i32 @assert(i32 %75)
%77 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 1
%78 = load i64, i64* %77
%79 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%80 = load i64, i64* %79
%81 = icmp eq i64 %78, %80
%82 = zext i1 %81 to i32
%83 = call i32 @assert(i32 %82)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
@.str = [2 x i8] c"/\00"
@O_DIRECTORY = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [17 x i8] c"/proc/self/fd/%u\00"
@.str.2 = [24 x i8] c"/proc/thread-self/fd/%u\00"
define i32 @main() {
%1 = alloca %struct.stat
%2 = alloca %struct.stat
%3 = alloca %struct.stat
%4 = alloca [64 x i8]
%5 = bitcast %struct.stat* %1 to i8*
%6 = bitcast %struct.stat* %2 to i8*
%7 = bitcast %struct.stat* %3 to i8*
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @O_DIRECTORY
%10 = load i32, i32* @O_RDONLY
%11 = or i32 %10, %9
%12 = tail call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = xor i32 %12, -1
%14 = lshr i32 %13, 31
%15 = tail call i32 @assert(i32 %14)
%16 = call i32 @snprintf(i8* %8, i32 64, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %8, i32 %17)
%19 = xor i32 %18, -1
%20 = lshr i32 %19, 31
%21 = call i32 @assert(i32 %20)
%22 = call i32 @snprintf(i8* %8, i32 64, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %8, i32 %23)
%25 = xor i32 %24, -1
%26 = lshr i32 %25, 31
%27 = call i32 @assert(i32 %26)
%28 = call i32 @fstat(i32 %12, %struct.stat* %1)
%29 = icmp eq i32 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = call i32 @fstat(i32 %18, %struct.stat* %2)
%33 = icmp eq i32 %32, 0
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = call i32 @fstat(i32 %24, %struct.stat* %3)
%37 = icmp eq i32 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%41 = load i64, i64* %40
%42 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%43 = load i64, i64* %42
%44 = icmp eq i64 %41, %43
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%48 = load i64, i64* %47
%49 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%50 = load i64, i64* %49
%51 = icmp eq i64 %48, %50
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%55 = load i64, i64* %54
%56 = icmp eq i64 %41, %55
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
%59 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%60 = load i64, i64* %59
%61 = icmp eq i64 %48, %60
%62 = zext i1 %61 to i32
%63 = call i32 @assert(i32 %62)
ret i32 0
}