#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*/ __gdb_close(int);
int __gdb_open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ __gdb_read(int, char *, int);
int /*<<< orphan*/ breakpoint3();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int main(void) {
  int fd;
  char buf[512];
  breakpoint3();
  fd = __gdb_open(".", O_RDONLY, 0777);
  fprintf(stderr, "fd %d\n", fd);
  __gdb_read(fd, buf, 512);
  __gdb_close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <breakpoint3@plt>
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
mov    $0x1ff,%edx
call   1070 <__gdb_open@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe69(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1050 <__gdb_read@plt>
mov    -0x8(%rbp),%edi
call   1060 <__gdb_close@plt>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x200,%rsp
xor    %eax,%eax
call   1040 <breakpoint3@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
mov    $0x1ff,%edx
call   1070 <__gdb_open@plt>
mov    %eax,%ebx
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
mov    %ebx,%edx
call   1030 <fprintf@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x200,%edx
call   1050 <__gdb_read@plt>
mov    %ebx,%edi
call   1060 <__gdb_close@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [7 x i8] c"fd %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [512 x i8]
store i32 0, i32* %1
%4 = call i32 (...) @breakpoint3()
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @__gdb_open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %5, i32 511)
store i32 %6, i32* %2
%7 = load i32, i32* @stderr
%8 = load i32, i32* %2
%9 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %2
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%12 = call i32 @__gdb_read(i32 %10, i8* %11, i32 512)
%13 = load i32, i32* %2
%14 = call i32 @__gdb_close(i32 %13)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [7 x i8] c"fd %d\0A\00"
define i32 @main() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @breakpoint3()
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @__gdb_open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %4, i32 511)
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%8 = call i32 @__gdb_read(i32 %5, i8* %2, i32 512)
%9 = call i32 @__gdb_close(i32 %5)
ret i32 0
}