#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*/ fname;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int MAXPATHLEN;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ stderr;
void installPython(const char *basedir, const char *version) {
  char fname[MAXPATHLEN];
  snprintf(fname, sizeof(fname), "/Library/Python/%s/site-packages/mitsuba.pth",
           version);
  FILE *f = fopen(fname, "w");
  if (!f) {
    fprintf(stderr, "Unable to write to file \"%s\"!\n", fname);
    exit(-1);
  }
  if (fprintf(f, "import sys; sys.path.append(\"%s/python/%s\")\n", basedir,
              version) < 1) {
    fprintf(stderr,
            "Unexpected I/O error while "
            "writing to \"%s\"!\n",
            fname);
    exit(-1);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<installPython>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
lea    0xe67(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e2 <installPython+0x92>
mov    -0x30(%rbp),%rdx
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rax
mov    %eax,%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmp    $0x1,%eax
jge    122c <installPython+0xdc>
mov    -0x30(%rbp),%rdx
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<installPython>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r12
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe7b(%rip),%rdx
mov    %r12,%rdi
mov    %r14,%rcx
call   1040 <snprintf@plt>
lea    0xe96(%rip),%rsi
mov    %r12,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d6 <installPython+0x86>
mov    %rax,%rbx
lea    0xea0(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %eax,%eax
jle    11e8 <installPython+0x98>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
jmp    11f8 <installPython+0xa8>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@.str = [45 x i8] c"/Library/Python/%s/site-packages/mitsuba.pth\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"Unable to write to file \22%s\22!\0A\00"
@.str.3 = [45 x i8] c"import sys; sys.path.append(\22%s/python/%s\22)\0A\00"
@.str.4 = [45 x i8] c"Unexpected I/O error while writing to \22%s\22!\0A\00"
define void @installPython(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i32, i32* @MAXPATHLEN
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
%12 = trunc i64 %9 to i32
%13 = load i8*, i8** %4
%14 = call i32 @snprintf(i8* %11, i32 %12, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %7
%16 = load i32*, i32** %7
%17 = icmp ne i32* %16, null
br i1 %17, label %22, label %18
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %2
%23 = load i32*, i32** %7
%24 = ptrtoint i32* %23 to i32
%25 = load i8*, i8** %3
%26 = load i8*, i8** %4
%27 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %25, i8* %26)
%28 = icmp slt i32 %27, 1
br i1 %28, label %29, label %33
29: ; preds = %22
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %22
%34 = load i32*, i32** %7
%35 = call i32 @fclose(i32* %34)
%36 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@.str = [45 x i8] c"/Library/Python/%s/site-packages/mitsuba.pth\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"Unable to write to file \22%s\22!\0A\00"
@.str.3 = [45 x i8] c"import sys; sys.path.append(\22%s/python/%s\22)\0A\00"
@.str.4 = [45 x i8] c"Unexpected I/O error while writing to \22%s\22!\0A\00"
define void @installPython(i8* %0, i8* %1) {
%3 = load i32, i32* @MAXPATHLEN
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @snprintf(i8* %5, i32 %3, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %1)
%7 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = ptrtoint i32* %7 to i64
%15 = trunc i64 %14 to i32
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %1)
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %5)
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %13
%23 = call i32 @fclose(i32* %7)
ret void
}