#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*/ DebugPostflight();
int /*<<< orphan*/ DebugPreflight(char *, int /*<<< orphan*/, int,
                                  int /*<<< orphan*/);
int /*<<< orphan*/ O_WRONLY;
char *calloc(int, int);
int /*<<< orphan*/ close(int);
int errno;
int open(char *, int /*<<< orphan*/);
int strlen(char *);
int main(int argc, char **argv) {
  int result = 0;
  char *buffer = NULL;
  int fd = 0;
  DebugPreflight("testapp", 0, -5, 0);
  do {
    ;
  } while (0);
  do {
    if ((buffer = calloc(1, 1)) == NULL) {
      do {
        ;
      } while (0);
      (void)0;
      goto CLEANUP;
    }
  } while (0);
  do {
    if (!!((fd = open("/dev/null", O_WRONLY)) < 0)) {
      do {
        ;
      } while (0);
      result = errno;
      goto CLEANUP;
    }
  } while (0);
  do {
    if (!(strlen("abc") == 3))
      do {
        ;
      } while (0);
  } while (0);
CLEANUP:
  if (fd)
    close(fd);
  DebugPostflight();
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe6d(%rip),%rdi
xor    %ecx,%ecx
mov    $0xfffffffb,%edx
mov    %ecx,%esi
call   1030 <DebugPreflight@plt>
jmp    11a6 <main+0x46>
jmp    11ab <main+0x4b>
mov    $0x1,%esi
mov    %esi,%edi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11d4 <main+0x74>
jmp    11ca <main+0x6a>
jmp    11cf <main+0x6f>
jmp    1252 <main+0xf2>
jmp    11d9 <main+0x79>
jmp    11de <main+0x7e>
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
lea    0xe1a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    121a <main+0xba>
jmp    1204 <main+0xa4>
jmp    1209 <main+0xa9>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1252 <main+0xf2>
jmp    121f <main+0xbf>
jmp    1224 <main+0xc4>
lea    0xde7(%rip),%rdi
call   1040 <strlen@plt>
cmp    $0x3,%eax
je     1248 <main+0xe8>
jmp    123e <main+0xde>
jmp    1243 <main+0xe3>
jmp    1248 <main+0xe8>
jmp    124d <main+0xed>
jmp    1252 <main+0xf2>
cmpl   $0x0,-0x24(%rbp)
je     1264 <main+0x104>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    $0x0,%al
call   1080 <DebugPostflight@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0xfffffffb,%edx
xor    %ecx,%ecx
call   1030 <DebugPreflight@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1197 <main+0x47>
lea    0xe86(%rip),%rdi
call   1040 <strlen@plt>
test   %ebp,%ebp
jne    11a0 <main+0x50>
jmp    11a7 <main+0x57>
mov    0x2e42(%rip),%rax
mov    (%rax),%ebx
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
call   1070 <DebugPostflight@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"testapp\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@errno = global i32 0
@.str.2 = [4 x i8] c"abc\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* null, i8** %7
store i32 0, i32* %8
%9 = call i32 @DebugPreflight(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 0, i32 -5, i32 0)
br label %10
10: ; preds = %2
br label %11
11: ; preds = %10
br label %12
12: ; preds = %11
%13 = call i8* @calloc(i32 1, i32 1)
store i8* %13, i8** %7
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
br label %16
16: ; preds = %15
br label %17
17: ; preds = %16
br label %38
18: ; preds = %12
br label %19
19: ; preds = %18
br label %20
20: ; preds = %19
%21 = load i32, i32* @O_WRONLY
%22 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %21)
store i32 %22, i32* %8
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %20
br label %25
25: ; preds = %24
br label %26
26: ; preds = %25
%27 = load i32, i32* @errno
store i32 %27, i32* %6
br label %38
28: ; preds = %20
br label %29
29: ; preds = %28
br label %30
30: ; preds = %29
%31 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i32 %31, 3
br i1 %32, label %36, label %33
33: ; preds = %30
br label %34
34: ; preds = %33
br label %35
35: ; preds = %34
br label %36
36: ; preds = %35, %30
br label %37
37: ; preds = %36
br label %38
38: ; preds = %37, %26, %17
%39 = load i32, i32* %8
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* %8
%43 = call i32 @close(i32 %42)
br label %44
44: ; preds = %41, %38
%45 = call i32 (...) @DebugPostflight()
%46 = load i32, i32* %6
ret i32 %46
}

LLVM IR (-O2):
@.str = [8 x i8] c"testapp\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@errno = global i32 0
@.str.2 = [4 x i8] c"abc\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @DebugPreflight(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 0, i32 -5, i32 0)
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = load i32, i32* @errno
br label %12
9: ; preds = %2
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32 %5, 0
br i1 %11, label %15, label %12
12: ; preds = %7, %9
%13 = phi i32 [ %8, %7 ], [ 0, %9 ]
%14 = tail call i32 @close(i32 %5)
br label %15
15: ; preds = %12, %9
%16 = phi i32 [ %13, %12 ], [ 0, %9 ]
%17 = tail call i32 (...) @DebugPostflight()
ret i32 %16
}