#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char);
int read(int, char *, int);
int main(int argc, const char **argv) {
  int fd;
  char buffer;
  if (-1 == (fd = open("/tmp/test", O_RDONLY))) {
    perror("open");
    return EXIT_FAILURE;
  }
  if (-1 == read(fd, &buffer, sizeof(char))) {
    perror("read");
    return EXIT_FAILURE;
  }
  printf("%c\n", buffer);
  close(fd);
  return EXIT_SUCCESS;
}


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    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11aa <main+0x5a>
lea    0xe76(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    120b <main+0xbb>
mov    -0x14(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11e7 <main+0x97>
lea    0xe3e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    120b <main+0xbb>
lea    0xe26(%rip),%rdi
movsbl -0x15(%rbp),%esi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11ae <main+0x5e>
mov    %eax,%ebx
lea    0xf(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     11b7 <main+0x67>
movsbl 0xf(%rsp),%esi
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe55(%rip),%rdi
jmp    11be <main+0x6e>
lea    0xe51(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e0e(%rip),%rax
jmp    11a6 <main+0x56>

LLVM IR (-O0):
@.str = [10 x i8] c"/tmp/test\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [4 x i8] c"%c\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = icmp eq i32 -1, %9
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %27
14: ; preds = %2
%15 = load i32, i32* %6
%16 = call i32 @read(i32 %15, i8* %7, i32 1)
%17 = icmp eq i32 -1, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
store i32 %20, i32* %3
br label %27
21: ; preds = %14
%22 = load i8, i8* %7
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %22)
%24 = load i32, i32* %6
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* @EXIT_SUCCESS
store i32 %26, i32* %3
br label %27
27: ; preds = %21, %18, %11
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [10 x i8] c"/tmp/test\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [4 x i8] c"%c\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %18
9: ; preds = %2
%10 = call i32 @read(i32 %5, i8* %3, i32 1)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %18
14: ; preds = %9
%15 = load i8, i8* %3
%16 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %15)
%17 = tail call i32 @close(i32 %5)
br label %18
18: ; preds = %14, %12, %7
%19 = phi i32* [ @EXIT_FAILURE, %7 ], [ @EXIT_FAILURE, %12 ], [ @EXIT_SUCCESS, %14 ]
%20 = load i32, i32* %19
ret i32 %20
}