#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 O_CREAT;
int O_RDWR;
int /*<<< orphan*/ __gdb_close(int);
int __gdb_open(char *, int, int);
int /*<<< orphan*/ __gdb_write(int, char *, int);
int /*<<< orphan*/ breakpoint3();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int main(void) {
  int fd;
  breakpoint3();
  fd = __gdb_open("a.tst", O_CREAT | O_RDWR, 0777);
  fprintf(stderr, "fd %d\n", fd);
  __gdb_write(fd, "test", 4);
  __gdb_close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <breakpoint3@plt>
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    0x2e6a(%rip),%rax
or     (%rax),%esi
lea    0xe81(%rip),%rdi
mov    $0x1ff,%edx
call   1070 <__gdb_open@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe67(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
lea    0xe5f(%rip),%rsi
mov    $0x4,%edx
call   1030 <__gdb_write@plt>
mov    -0x8(%rbp),%edi
call   1060 <__gdb_close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1050 <breakpoint3@plt>
mov    0x2e99(%rip),%rax
mov    0x2e7a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe8f(%rip),%rdi
mov    $0x1ff,%edx
call   1070 <__gdb_open@plt>
mov    %eax,%ebx
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
lea    0xe72(%rip),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <__gdb_write@plt>
mov    %ebx,%edi
call   1060 <__gdb_close@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"a.tst\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [7 x i8] c"fd %d\0A\00"
@.str.2 = [5 x i8] c"test\00"
define i32 @main() {
%1 = tail call i32 (...) @breakpoint3()
%2 = load i32, i32* @O_CREAT
%3 = load i32, i32* @O_RDWR
%4 = or i32 %3, %2
%5 = tail call i32 @__gdb_open(i8* getelementptr inbounds ([6 x i8], [6 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 = tail call i32 @__gdb_write(i32 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%9 = tail call i32 @__gdb_close(i32 %5)
ret i32 0
}