#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
FILE *my_open(char *directory, char *file) {
  char path[8192];
  FILE *r;
  strcpy(path, directory);
  strcat(path, "/");
  strcat(path, file);
  r = fopen(path, "r");
  if (r == NULL) {
    fprintf(stderr, "Could not open %s\n", path);
    perror("open");
    exit(1);
  }
  return r;
}


x86 assembly (clang, -O0):
<my_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x2010(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x2010(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <strcat@plt>
lea    -0x2010(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
lea    -0x2010(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x2018(%rbp)
cmpq   $0x0,-0x2018(%rbp)
jne    1200 <my_open+0xa0>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    -0x2010(%rbp),%rdx
lea    0xe1f(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xe26(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x2018(%rbp),%rax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_open>:
push   %r14
push   %rbx
sub    $0x2008,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
lea    0xe66(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11b4 <my_open+0x54>
add    $0x2008,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
mov    %rsp,%rdx
call   1040 <fprintf@plt>
lea    0xe44(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [19 x i8] c"Could not open %s\0A\00"
@.str.3 = [5 x i8] c"open\00"
define i32* @my_open(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [8192 x i8]
%6 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @strcpy(i8* %7, i8* %8)
%10 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%11 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%13 = load i8*, i8** %4
%14 = call i32 @strcat(i8* %12, i8* %13)
%15 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %25
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = load i32*, i32** %6
ret i32* %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [19 x i8] c"Could not open %s\0A\00"
@.str.3 = [5 x i8] c"open\00"
define noalias i32* @my_open(i8* %0, i8* %1) {
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* %0)
%6 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @strcat(i8* %4, i8* %1)
%8 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%13 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
ret i32* %8
}