#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_CREAT;
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, char *, ...);
int main(void) {
  int fd;
  char *leds = "/dev/leds";
  char *leds1 = "/bin/test1";
  char *leds2 = "/dev/test2";
  if ((fd = open(leds, O_RDWR | O_NOCTTY | O_NDELAY)) < 0) {
    printf("open %s failed!\n", leds);
  }
  printf("%s fd is = %d\n", leds, fd);
  if ((fd = open(leds1, O_RDWR, 777)) < 0) {
    printf("open %s failed!\n", leds1);
  }
  printf("%s fd is = %d\n", leds1, fd);
  if ((fd = open(leds2, O_RDWR | O_CREAT, 777)) < 0) {
    printf("open %s failed!\n", leds2);
  }
  printf("%s fd is = %d\n", leds2, fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xec9(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xec9(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    0x2e6c(%rip),%rax
or     (%rax),%esi
mov    0x2e5b(%rip),%rax
or     (%rax),%esi
mov    $0x0,%al
call   1040 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1194 <main+0x74>
mov    -0x10(%rbp),%rsi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    $0x309,%edx
mov    $0x0,%al
call   1040 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11e0 <main+0xc0>
mov    -0x18(%rbp),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
mov    0x2def(%rip),%rax
or     (%rax),%esi
mov    $0x309,%edx
mov    $0x0,%al
call   1040 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1235 <main+0x115>
mov    -0x20(%rbp),%rsi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2eb5(%rip),%r14
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
or     (%r14),%esi
mov    0x2e8a(%rip),%rax
or     (%rax),%esi
lea    0xeb9(%rip),%rdi
xor    %eax,%eax
call   1040 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1169 <main+0x49>
lea    0xec5(%rip),%rdi
lea    0xe9e(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
lea    0xe89(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r14),%esi
lea    0xe80(%rip),%rdi
mov    $0x309,%edx
xor    %eax,%eax
call   1040 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11b1 <main+0x91>
lea    0xe7d(%rip),%rdi
lea    0xe60(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe79(%rip),%rdi
lea    0xe4b(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
or     (%r14),%esi
lea    0xe3a(%rip),%rdi
mov    $0x309,%edx
xor    %eax,%eax
call   1040 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1202 <main+0xe2>
lea    0xe2c(%rip),%rdi
lea    0xe1a(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe28(%rip),%rdi
lea    0xe05(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/leds\00"
@.str.1 = [11 x i8] c"/bin/test1\00"
@.str.2 = [11 x i8] c"/dev/test2\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.3 = [17 x i8] c"open %s failed!\0A\00"
@.str.4 = [15 x i8] c"%s fd is = %d\0A\00"
@O_CREAT = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** %5
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_NOCTTY
%9 = or i32 %7, %8
%10 = load i32, i32* @O_NDELAY
%11 = or i32 %9, %10
%12 = call i32 (i8*, i32, ...) @open(i8* %6, i32 %11)
store i32 %12, i32* %2
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = load i8*, i8** %3
%16 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14, %0
%18 = load i8*, i8** %3
%19 = load i32, i32* %2
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %18, i32 %19)
%21 = load i8*, i8** %4
%22 = load i32, i32* @O_RDWR
%23 = call i32 (i8*, i32, ...) @open(i8* %21, i32 %22, i32 777)
store i32 %23, i32* %2
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load i8*, i8** %4
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %17
%29 = load i8*, i8** %4
%30 = load i32, i32* %2
%31 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %29, i32 %30)
%32 = load i8*, i8** %5
%33 = load i32, i32* @O_RDWR
%34 = load i32, i32* @O_CREAT
%35 = or i32 %33, %34
%36 = call i32 (i8*, i32, ...) @open(i8* %32, i32 %35, i32 777)
store i32 %36, i32* %2
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %28
%39 = load i8*, i8** %5
%40 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %38, %28
%42 = load i8*, i8** %5
%43 = load i32, i32* %2
%44 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %42, i32 %43)
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/leds\00"
@.str.1 = [11 x i8] c"/bin/test1\00"
@.str.2 = [11 x i8] c"/dev/test2\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.3 = [17 x i8] c"open %s failed!\0A\00"
@.str.4 = [15 x i8] c"%s fd is = %d\0A\00"
@O_CREAT = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = load i32, i32* @O_NOCTTY
%3 = or i32 %2, %1
%4 = load i32, i32* @O_NDELAY
%5 = or i32 %3, %4
%6 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6)
%12 = load i32, i32* @O_RDWR
%13 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 777)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
%18 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%19 = load i32, i32* @O_RDWR
%20 = load i32, i32* @O_CREAT
%21 = or i32 %20, %19
%22 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 777)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %17
%27 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %22)
ret i32 0
}