#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
int main() {
  int fd;
  char buf[512];
  fd = open("/tmp/tes.txt", O_RDONLY);
  if (fd < 0) {
    printf("cannot open file\n");
    return -1;
  }
  read(fd, buf, sizeof(buf));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
lea    0xeae(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    117c <main+0x4c>
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <main+0x67>
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1040 <read@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x208,%rsp
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
lea    0xeb9(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     1169 <main+0x39>
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x200,%edx
call   1040 <read@plt>
xor    %eax,%eax
add    $0x208,%rsp
ret
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x208,%rsp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/tmp/tes.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"cannot open file\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [512 x i8]
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %14
10: ; preds = %0
%11 = load i32, i32* %2
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 512)
store i32 0, i32* %1
br label %14
14: ; preds = %10, %8
%15 = load i32, i32* %1
ret i32 %15
}

LLVM IR (-O2):
@.str = [13 x i8] c"/tmp/tes.txt\00"
@O_RDONLY = global i32 0
@str = [17 x i8] c"cannot open file\00"
define i32 @main() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %10
8: ; preds = %0
%9 = call i32 @read(i32 %4, i8* %2, i32 512)
br label %10
10: ; preds = %8, %6
%11 = phi i32 [ -1, %6 ], [ 0, %8 ]
ret i32 %11
}