#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 getpid();
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int /*<<< orphan*/ read(unsigned int, unsigned int *, int);
int strlen(char const *);
int /*<<< orphan*/ write(int, char *, int);
int open(const char *pathname, int flags) {
  unsigned int replyfd = getpid() + 3;
  size_t plen = strlen(pathname) + 1;
  unsigned int fd = -1;
  char buf[4 + 4 + 255];
  (void)flags;
  *((unsigned int *)buf) = replyfd;
  *((unsigned int *)(buf + 4)) = plen;
  memcpy(buf + 4 + 4, pathname, plen);
  write((10 + 3), buf, 4 + 4 + plen);
  read(replyfd, &fd, 4);
  return fd;
}


x86 assembly (clang, -O0):
<open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
add    $0x3,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,-0x12c(%rbp)
lea    -0x130(%rbp),%rdi
add    $0x4,%rdi
add    $0x4,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <memcpy@plt>
lea    -0x130(%rbp),%rsi
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %eax,%edx
mov    $0xd,%edi
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    -0x1c(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open>:
push   %rbp
push   %r14
push   %rbx
sub    $0x120,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0x3(%rax),%r14d
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
lea    0x1(%rbp),%eax
movslq %eax,%rdx
movl   $0xffffffff,0xc(%rsp)
ff
mov    %r14d,0x10(%rsp)
mov    %edx,0x14(%rsp)
lea    0x18(%rsp),%rdi
mov    %rbx,%rsi
call   1070 <memcpy@plt>
add    $0x9,%ebp
lea    0x10(%rsp),%rsi
mov    $0xd,%edi
mov    %ebp,%edx
call   1030 <write@plt>
lea    0xc(%rsp),%rsi
mov    %r14d,%edi
mov    $0x4,%edx
call   1060 <read@plt>
mov    0xc(%rsp),%eax
add    $0x120,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @open(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca [263 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = call i32 (...) @getpid()
%10 = add nsw i32 %9, 3
store i32 %10, i32* %5
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 1
%14 = sext i32 %13 to i64
store i64 %14, i64* %6
store i32 -1, i32* %7
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = getelementptr inbounds [263 x i8], [263 x i8]* %8, i64 0, i64 0
%18 = bitcast i8* %17 to i32*
store i32 %16, i32* %18
%19 = load i64, i64* %6
%20 = trunc i64 %19 to i32
%21 = getelementptr inbounds [263 x i8], [263 x i8]* %8, i64 0, i64 0
%22 = getelementptr inbounds i8, i8* %21, i64 4
%23 = bitcast i8* %22 to i32*
store i32 %20, i32* %23
%24 = getelementptr inbounds [263 x i8], [263 x i8]* %8, i64 0, i64 0
%25 = getelementptr inbounds i8, i8* %24, i64 4
%26 = getelementptr inbounds i8, i8* %25, i64 4
%27 = load i8*, i8** %3
%28 = load i64, i64* %6
%29 = call i32 @memcpy(i8* %26, i8* %27, i64 %28)
%30 = getelementptr inbounds [263 x i8], [263 x i8]* %8, i64 0, i64 0
%31 = load i64, i64* %6
%32 = add i64 8, %31
%33 = trunc i64 %32 to i32
%34 = call i32 @write(i32 13, i8* %30, i32 %33)
%35 = load i32, i32* %5
%36 = call i32 @read(i32 %35, i32* %7, i32 4)
%37 = load i32, i32* %7
ret i32 %37
}

LLVM IR (-O2):
define i32 @open(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca [263 x i8]
%5 = tail call i32 (...) @getpid()
%6 = add nsw i32 %5, 3
%7 = tail call i32 @strlen(i8* %0)
%8 = add nsw i32 %7, 1
%9 = sext i32 %8 to i64
%10 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%11 = getelementptr inbounds [263 x i8], [263 x i8]* %4, i64 0, i64 0
%12 = bitcast [263 x i8]* %4 to i32*
store i32 %6, i32* %12
%13 = getelementptr inbounds [263 x i8], [263 x i8]* %4, i64 0, i64 4
%14 = bitcast i8* %13 to i32*
store i32 %8, i32* %14
%15 = getelementptr inbounds [263 x i8], [263 x i8]* %4, i64 0, i64 8
%16 = call i32 @memcpy(i8* %15, i8* %0, i64 %9)
%17 = add i32 %7, 9
%18 = call i32 @write(i32 13, i8* %11, i32 %17)
%19 = call i32 @read(i32 %6, i32* %3, i32 4)
%20 = load i32, i32* %3
ret i32 %20
}