#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*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  int fd;
  int rc = 0;
  char *rd_buf[16];
  int ret;
  printf("%s: entered\n", argv[0]);
  fd = open("/dev/cdata", O_RDWR);
  if (fd == -1) {
    perror("open failed");
    rc = fd;
    exit(-1);
  }
  printf("%s: open: successful\n", argv[0]);
  while (1) {
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b1 <main+0x71>
lea    0xe7c(%rip),%rdi
call   1050 <perror@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
jmp    11c4 <main+0x84>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
mov    (%rsi),%rsi
lea    0xeb2(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
lea    0xeaa(%rip),%rdi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
je     1182 <main+0x42>
mov    (%rbx),%rsi
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
nopl   0x0(%rax)
jmp    1180 <main+0x40>
lea    0xe8f(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"%s: entered\0A\00"
@.str.1 = [11 x i8] c"/dev/cdata\00"
@O_RDWR = global i32 0
@.str.2 = [12 x i8] c"open failed\00"
@.str.3 = [22 x i8] c"%s: open: successful\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [16 x i8*]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @O_RDWR
%15 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* %6
store i32 %20, i32* %7
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %22, %27
br label %27
}

LLVM IR (-O2):
@.str = [13 x i8] c"%s: entered\0A\00"
@.str.1 = [11 x i8] c"/dev/cdata\00"
@O_RDWR = global i32 0
@.str.2 = [12 x i8] c"open failed\00"
@.str.3 = [22 x i8] c"%s: open: successful\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = load i8*, i8** %1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %14, %11
br label %14
}