#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 */

/* Variables and functions */
int O_EXCL;
int O_RDONLY;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int is_on_physical_device(int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int ret, fd;
  if (argc < 2) {
    fprintf(stderr, "usage: %s <file> \n", argv[0]);
    return -1;
  }
  fd = open(argv[1], O_RDONLY | O_EXCL, 0644);
  if (fd == -1) {
    perror("open");
    return -1;
  }
  ret = is_on_physical_device(fd);
  if (ret == 0)
    printf("On virtual device( NFS?)\n");
  else
    printf("On physical device...\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1198 <main+0x48>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <main+0xca>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
mov    0x2e20(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11e1 <main+0x91>
lea    0xe43(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <main+0xca>
mov    -0x18(%rbp),%edi
call   1030 <is_on_physical_device@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1207 <main+0xb7>
lea    0xe1b(%rip),%rdi
call   1040 <printf@plt>
jmp    1213 <main+0xc3>
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x1,%edi
jg     1175 <main+0x25>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe97(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
mov    0x8(%rsi),%rdi
mov    0x2e68(%rip),%rax
mov    0x2e49(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1a4,%edx
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11be <main+0x6e>
mov    %eax,%edi
call   1030 <is_on_physical_device@plt>
test   %eax,%eax
je     11ae <main+0x5e>
lea    0xe6c(%rip),%rdi
jmp    11b5 <main+0x65>
lea    0xe79(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe4e(%rip),%rdi
call   1070 <perror@plt>
jmp    116e <main+0x1e>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"usage: %s <file> \0A\00"
@O_RDONLY = global i32 0
@O_EXCL = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [26 x i8] c"On virtual device( NFS?)\0A\00"
@.str.3 = [23 x i8] c"On physical device...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 -1, i32* %3
br label %38
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = load i32, i32* @O_EXCL
%22 = or i32 %20, %21
%23 = call i32 @open(i8* %19, i32 %22, i32 420)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %16
%27 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %38
28: ; preds = %16
%29 = load i32, i32* %7
%30 = call i32 @is_on_physical_device(i32 %29)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %37
35: ; preds = %28
%36 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %33
store i32 0, i32* %3
br label %38
38: ; preds = %37, %26, %10
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"usage: %s <file> \0A\00"
@O_RDONLY = global i32 0
@O_EXCL = global i32 0
@.str.1 = [5 x i8] c"open\00"
@str = [22 x i8] c"On physical device...\00"
@str.4 = [25 x i8] c"On virtual device( NFS?)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %25
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = load i32, i32* @O_EXCL
%13 = or i32 %12, %11
%14 = tail call i32 @open(i8* %10, i32 %13, i32 420)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %25
18: ; preds = %8
%19 = tail call i32 @is_on_physical_device(i32 %14)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.4, i64 0, i64 0))
br label %25
23: ; preds = %18
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %25
25: ; preds = %21, %23, %16, %4
%26 = phi i32 [ -1, %4 ], [ -1, %16 ], [ 0, %23 ], [ 0, %21 ]
ret i32 %26
}