#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 O_EXCL;
int O_RDONLY;
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read_all(int, char *, int);
int main(int argc, char *argv[]) {
  int fd;
  char buf[256] = {0};
  fd = open("test.log", O_RDONLY | O_EXCL, 0644);
  read_all(fd, buf, sizeof(buf));
  printf("buf: %s\n", buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    0x2e5c(%rip),%rax
or     (%rax),%esi
lea    0xe7b(%rip),%rdi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read_all@plt>
lea    -0x120(%rbp),%rsi
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    0x2e3f(%rip),%rax
mov    0x2e28(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe45(%rip),%rdi
mov    $0x1a4,%edx
call   1040 <open@plt>
mov    %rsp,%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1050 <read_all@plt>
lea    0xe2b(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"test.log\00"
@O_RDONLY = global i32 0
@O_EXCL = global i32 0
@.str.1 = [9 x i8] c"buf: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [256 x i8]* %7 to i8*
%9 = load i32, i32* @O_RDONLY
%10 = load i32, i32* @O_EXCL
%11 = or i32 %9, %10
%12 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11, i32 420)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%15 = call i32 @read_all(i32 %13, i8* %14, i32 256)
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %16)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.log\00"
@O_RDONLY = global i32 0
@O_EXCL = global i32 0
@.str.1 = [9 x i8] c"buf: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = load i32, i32* @O_EXCL
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7, i32 420)
%9 = call i32 @read_all(i32 %8, i8* %4, i32 256)
%10 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %4)
ret i32 0
}