#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_RDONLY;
int /*<<< orphan*/ die(char *, ...);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int write(int, char *, int);
int main(void) {
  char *file = "xopenread.txt";
  char buf[100];
  int len;
  int wrt;
  int fd = open(file, O_RDONLY);
  len = read(fd, buf, 100);
  if (len < 0)
    die("Can't read %s: %m\n", file);
  wrt = write(1, buf, len);
  if (wrt < 0)
    die("Can't dump data to stdout: %m\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1040 <read@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jge    11ae <main+0x6e>
mov    -0x10(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1060 <die@plt>
lea    -0x80(%rbp),%rsi
mov    -0x84(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    %eax,-0x88(%rbp)
cmpl   $0x0,-0x88(%rbp)
jge    11e3 <main+0xa3>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1060 <die@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    0xeab(%rip),%rdi
call   1050 <open@plt>
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x64,%edx
call   1040 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1184 <main+0x44>
lea    0xe98(%rip),%rdi
lea    0xe83(%rip),%rsi
xor    %eax,%eax
call   1060 <die@plt>
mov    %rsp,%rsi
mov    $0x1,%edi
mov    %ebx,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    11a5 <main+0x65>
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1060 <die@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"xopenread.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"Can't read %s: %m\0A\00"
@.str.2 = [31 x i8] c"Can't dump data to stdout: %m\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %2
%7 = load i8*, i8** %2
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 100)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = load i8*, i8** %2
%17 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %15, %0
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%20 = load i32, i32* %4
%21 = call i32 @write(i32 1, i8* %19, i32 %20)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %18
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"xopenread.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"Can't read %s: %m\0A\00"
@.str.2 = [31 x i8] c"Can't dump data to stdout: %m\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32 @read(i32 %4, i8* %2, i32 100)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = call i32 @write(i32 1, i8* %2, i32 %5)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
ret i32 0
}