#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int pluto_fd = open("/dev/pluto", O_RDWR);
  if (0 > pluto_fd) {
    printf("Open pluto failed\n");
    return 0;
  }
  ioctl(pluto_fd, 3, 97123);
  close(pluto_fd);
  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)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jle    1191 <main+0x51>
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b2 <main+0x72>
mov    -0x14(%rbp),%edi
mov    $0x3,%esi
mov    $0x17b63,%edx
call   1040 <ioctl@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    0xeaf(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1176 <main+0x36>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x3,%esi
mov    $0x17b63,%edx
call   1040 <ioctl@plt>
mov    %ebx,%edi
call   1050 <close@plt>
jmp    1182 <main+0x42>
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/pluto\00"
@O_RDWR = global i32 0
@.str.1 = [19 x i8] c"Open pluto failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp sgt i32 0, %9
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %18
13: ; preds = %2
%14 = load i32, i32* %6
%15 = call i32 @ioctl(i32 %14, i32 3, i32 97123)
%16 = load i32, i32* %6
%17 = call i32 @close(i32 %16)
store i32 0, i32* %3
br label %18
18: ; preds = %13, %11
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/pluto\00"
@O_RDWR = global i32 0
@str = [18 x i8] c"Open pluto failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %11
8: ; preds = %2
%9 = tail call i32 @ioctl(i32 %4, i32 3, i32 97123)
%10 = tail call i32 @close(i32 %4)
br label %11
11: ; preds = %8, %6
ret i32 0
}