#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 *getenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
FILE *bfopen(char name[], char flags[]) {
  char *cptr;
  char fulname[512];
  if ((cptr = getenv("BOITHOHOME")) == NULL) {
    fprintf(stderr, "Error: Can't get environment value \"BOITHOHOME\"");
    exit(-1);
  } else if (name[0] == '/') {
    fprintf(stderr,
            "Error: name starts with a /. Yoy must use virtual adressing\n");
    exit(-1);
  } else {
    sprintf(fulname, "%s/%s", cptr, name);
    return fopen(fulname, flags);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<bfopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe96(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    119c <bfopen+0x4c>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11cb <bfopen+0x7b>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe97(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <fopen@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bfopen>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe97(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11a8 <bfopen+0x58>
cmpb   $0x2f,(%rbx)
je     11ba <bfopen+0x6a>
lea    0xef9(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1060 <sprintf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <fopen@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
jmp    11ca <bfopen+0x7a>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"BOITHOHOME\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"Error: Can't get environment value \22BOITHOHOME\22\00"
@.str.2 = [61 x i8] c"Error: name starts with a /. Yoy must use virtual adressing\0A\00"
@.str.3 = [6 x i8] c"%s/%s\00"
define i32* @bfopen(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [512 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %5
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 47
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %13
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%25 = load i8*, i8** %5
%26 = load i8*, i8** %3
%27 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %25, i8* %26)
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%29 = load i8*, i8** %4
%30 = call i32* @fopen(i8* %28, i8* %29)
ret i32* %30
}

LLVM IR (-O2):
@.str = [11 x i8] c"BOITHOHOME\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"Error: Can't get environment value \22BOITHOHOME\22\00"
@.str.2 = [61 x i8] c"Error: name starts with a /. Yoy must use virtual adressing\0A\00"
@.str.3 = [6 x i8] c"%s/%s\00"
define noalias i32* @bfopen(i8* %0, i8* nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = load i8, i8* %0
%13 = icmp eq i8 %12, 47
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %11
%19 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %5, i8* %0)
%20 = call i32* @fopen(i8* %4, i8* %1)
ret i32* %20
}