#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_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  int fd;
  fd = open("/dev/misc_node", O_RDONLY);
  if (fd < 0) {
    printf("open /dev/misc_node failed!\n");
    return -1;
  }
  printf("open /dev/misc_node ok!\n");
  if (ioctl(fd, 6) != 0) {
    printf("ioctl failed!\n");
  } else {
    printf("ioctl ok!\n");
  }
  close(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)
cmpl   $0x0,-0x14(%rbp)
jge    1190 <main+0x50>
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <main+0x9f>
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x6,%esi
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     11c4 <main+0x84>
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
jmp    11d0 <main+0x90>
lea    0xe89(%rip),%rdi
call   1030 <printf@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     1199 <main+0x59>
mov    %eax,%ebx
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    $0x6,%esi
call   1040 <ioctl@plt>
test   %rax,%rax
lea    0xea9(%rip),%rax
lea    0xeac(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/misc_node\00"
@O_RDONLY = global i32 0
@.str.1 = [29 x i8] c"open /dev/misc_node failed!\0A\00"
@.str.2 = [25 x i8] c"open /dev/misc_node ok!\0A\00"
@.str.3 = [15 x i8] c"ioctl failed!\0A\00"
@.str.4 = [11 x i8] c"ioctl ok!\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_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %25
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* %6
%16 = call i64 @ioctl(i32 %15, i32 6)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %22
20: ; preds = %13
%21 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
%23 = load i32, i32* %6
%24 = call i32 @close(i32 %23)
store i32 0, i32* %3
br label %25
25: ; preds = %22, %11
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/misc_node\00"
@O_RDONLY = global i32 0
@str = [24 x i8] c"open /dev/misc_node ok!\00"
@str.5 = [10 x i8] c"ioctl ok!\00"
@str.6 = [14 x i8] c"ioctl failed!\00"
@str.7 = [28 x i8] c"open /dev/misc_node failed!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 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 ([28 x i8], [28 x i8]* @str.7, i64 0, i64 0))
br label %15
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%10 = tail call i64 @ioctl(i32 %4, i32 6)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0)
%13 = tail call i32 @puts(i8* dereferenceable(1) %12)
%14 = tail call i32 @close(i32 %4)
br label %15
15: ; preds = %8, %6
%16 = phi i32 [ -1, %6 ], [ 0, %8 ]
ret i32 %16
}