#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 open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  char buff[1000];
  int x = open(argv[1], O_RDONLY);
  int s = read(x, buff, 1000);
  printf("%d\n", x);
  write(1, buff, s);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x404(%rbp)
mov    -0x404(%rbp),%edi
lea    -0x400(%rbp),%rsi
mov    $0x3e8,%edx
call   1050 <read@plt>
mov    %eax,-0x408(%rbp)
mov    -0x404(%rbp),%esi
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
lea    -0x400(%rbp),%rsi
mov    -0x408(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3f0,%rsp
mov    0x8(%rsi),%rdi
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x3e8,%edx
call   1050 <read@plt>
mov    %eax,%ebp
lea    0xe86(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [1000 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i8**, i8*** %4
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%15 = call i32 @read(i32 %13, i8* %14, i32 1000)
store i32 %15, i32* %7
%16 = load i32, i32* %6
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%19 = load i32, i32* %7
%20 = call i32 @write(i32 1, i8* %18, i32 %19)
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = call i32 @read(i32 %8, i8* %4, i32 1000)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %8)
%11 = call i32 @write(i32 1, i8* %4, i32 %9)
ret i32 0
}