#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_NDELAY;
int O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, char *);
main() {
  int fd;
  char *hello_node = "/dev/hello_ctl123";
  if ((fd = open(hello_node, O_RDWR | O_NDELAY)) < 0) {
    printf("APP open %s failed", hello_node);
  } else {
    printf("APP open %s success", hello_node);
    ioctl(fd, 1, 6);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    0x2e6a(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1196 <main+0x56>
mov    -0x10(%rbp),%rsi
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
jmp    11b8 <main+0x78>
mov    -0x10(%rbp),%rsi
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
mov    $0x6,%edx
call   1040 <ioctl@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    0x2e89(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xea6(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     118b <main+0x4b>
lea    0xeb9(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1030 <printf@plt>
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x6,%edx
call   1040 <ioctl@plt>
jmp    119e <main+0x5e>
lea    0xe80(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [18 x i8] c"/dev/hello_ctl123\00"
@O_RDWR = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [19 x i8] c"APP open %s failed\00"
@.str.2 = [20 x i8] c"APP open %s success\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = load i32, i32* @O_NDELAY
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %11
8: ; preds = %0
%9 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @ioctl(i32 %4, i32 1, i32 6)
br label %11
11: ; preds = %8, %6
%12 = tail call i32 @close(i32 %4)
ret i32 0
}