#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*/ *fopen(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
FILE *osx_open_file(char *fn, int dim_file, char *exe_path, char *mode) {
  int path_len = strlen(exe_path);
  char new_path[path_len + dim_file + 1];
  int i = path_len;
  while (exe_path[i] != '/' && i > 0)
    i--;
  exe_path[i] = '\0';
  strcpy(new_path, exe_path);
  strcat(new_path, fn);
  return fopen(new_path, mode);
}


x86 assembly (clang, -O0):
<osx_open_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edx
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
mov    %edx,%eax
lea    0x1(%rax,%rcx,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x49(%rbp)
je     11be <osx_open_file+0x7e>
cmpl   $0x0,-0x3c(%rbp)
setg   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    11ce <osx_open_file+0x8e>
jmp    11dc <osx_open_file+0x9c>
mov    -0x3c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x3c(%rbp)
jmp    119a <osx_open_file+0x5a>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fopen@plt>
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<osx_open_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%r12d
mov    %rdi,%r15
mov    %rdx,%rdi
call   1040 <strlen@plt>
lea    (%r12,%rax,1),%ecx
add    $0x1,%ecx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%r12
sub    %rcx,%r12
mov    %r12,%rsp
cltq
nopl   0x0(%rax)
lea    -0x1(%rax),%rcx
cmpb   $0x2f,(%rbx,%rax,1)
je     1192 <osx_open_file+0x52>
test   %rax,%rax
mov    %rcx,%rax
jg     1180 <osx_open_file+0x40>
movb   $0x0,0x1(%rbx,%rcx,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <fopen@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @osx_open_file(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%13 = load i8*, i8** %7
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = load i32, i32* %6
%17 = add nsw i32 %15, %16
%18 = add nsw i32 %17, 1
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %10
%21 = alloca i8, i64 %19
store i64 %19, i64* %11
%22 = load i32, i32* %9
store i32 %22, i32* %12
br label %23
23: ; preds = %36, %4
%24 = load i8*, i8** %7
%25 = load i32, i32* %12
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 47
br i1 %30, label %31, label %34
31: ; preds = %23
%32 = load i32, i32* %12
%33 = icmp sgt i32 %32, 0
br label %34
34: ; preds = %31, %23
%35 = phi i1 [ false, %23 ], [ %33, %31 ]
br i1 %35, label %36, label %39
36: ; preds = %34
%37 = load i32, i32* %12
%38 = add nsw i32 %37, -1
store i32 %38, i32* %12
br label %23
39: ; preds = %34
%40 = load i8*, i8** %7
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 0, i8* %43
%44 = load i8*, i8** %7
%45 = call i32 @strcpy(i8* %21, i8* %44)
%46 = load i8*, i8** %5
%47 = call i32 @strcat(i8* %21, i8* %46)
%48 = load i8*, i8** %8
%49 = call i32* @fopen(i8* %21, i8* %48)
%50 = load i8*, i8** %10
ret i32* %49
}

LLVM IR (-O2):
define noalias i32* @osx_open_file(i8* %0, i32 %1, i8* %2, i8* nocapture %3) {
%5 = tail call i32 @strlen(i8* %2)
%6 = add i32 %1, 1
%7 = add i32 %6, %5
%8 = zext i32 %7 to i64
%9 = alloca i8, i64 %8
%10 = sext i32 %5 to i64
br label %11
11: ; preds = %11, %4
%12 = phi i64 [ %18, %11 ], [ %10, %4 ]
%13 = getelementptr inbounds i8, i8* %2, i64 %12
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 47
%16 = icmp sgt i64 %12, 0
%17 = select i1 %15, i1 %16, i1 false
%18 = add nsw i64 %12, -1
br i1 %17, label %11, label %19
19: ; preds = %11
%20 = getelementptr inbounds i8, i8* %2, i64 %12
store i8 0, i8* %20
%21 = call i32 @strcpy(i8* %9, i8* %2)
%22 = call i32 @strcat(i8* %9, i8* %0)
%23 = call i32* @fopen(i8* %9, i8* %3)
ret i32* %23
}