#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 S_IRGRP;
int S_IROTH;
int S_IRWXU;
int S_IXGRP;
int S_IXOTH;
scalar_t__ chmod(char *, int);
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 install(const char *basedir, const char *name) {
  char fname[MAXPATHLEN];
  FILE *f;
  snprintf(fname, sizeof(fname), "/usr/bin/%s", name);
  f = fopen(fname, "w");
  if (!f) {
    fprintf(stderr, "Unable to write to file \"%s\"!\n", fname);
    exit(-1);
  }
  if (fprintf(f, "%s/Contents/MacOS/%s $@\n", basedir, name) < 1) {
    fprintf(stderr,
            "Unexpected I/O error while "
            "writing to \"%s\"!\n",
            fname);
    exit(-1);
  }
  fclose(f);
  if (chmod(fname, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) {
    fprintf(stderr,
            "Unexpected I/O error while setting "
            "the permssions of \"%s\"!\n",
            fname);
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<install>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e61(%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    0xe57(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f2 <install+0x92>
mov    -0x30(%rbp),%rdx
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rax
mov    %eax,%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmp    $0x1,%eax
jge    123c <install+0xdc>
mov    -0x30(%rbp),%rdx
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
mov    0x2d5f(%rip),%rax
or     (%rax),%esi
mov    0x2d6e(%rip),%rax
or     (%rax),%esi
mov    0x2d45(%rip),%rax
or     (%rax),%esi
mov    0x2d6c(%rip),%rax
or     (%rax),%esi
call   1060 <chmod@plt>
cmp    $0x0,%rax
je     12aa <install+0x14a>
mov    -0x30(%rbp),%rdx
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<install>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r12
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe6b(%rip),%rdx
mov    %r12,%rdi
mov    %r14,%rcx
call   1040 <snprintf@plt>
lea    0xe65(%rip),%rsi
mov    %r12,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1220 <install+0xc0>
mov    %rax,%rbx
lea    0xe6f(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %eax,%eax
jle    1232 <install+0xd2>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2e08(%rip),%rax
mov    0x2dd1(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dde(%rip),%rax
or     (%rax),%esi
mov    0x2db5(%rip),%rax
or     (%rax),%esi
mov    0x2ddc(%rip),%rax
or     (%rax),%esi
mov    %r12,%rdi
call   1060 <chmod@plt>
test   %rax,%rax
jne    1244 <install+0xe4>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
lea    0xdde(%rip),%rsi
jmp    1254 <install+0xf4>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
jmp    1254 <install+0xf4>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@.str = [12 x i8] c"/usr/bin/%s\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 = [25 x i8] c"%s/Contents/MacOS/%s $@\0A\00"
@.str.4 = [45 x i8] c"Unexpected I/O error while writing to \22%s\22!\0A\00"
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@.str.5 = [60 x i8] c"Unexpected I/O error while setting the permssions of \22%s\22!\0A\00"
define void @install(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 ([12 x i8], [12 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 ([25 x i8], [25 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 i32, i32* @S_IRWXU
%37 = load i32, i32* @S_IRGRP
%38 = or i32 %36, %37
%39 = load i32, i32* @S_IXGRP
%40 = or i32 %38, %39
%41 = load i32, i32* @S_IROTH
%42 = or i32 %40, %41
%43 = load i32, i32* @S_IXOTH
%44 = or i32 %42, %43
%45 = call i64 @chmod(i8* %11, i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %33
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i8* %11)
%50 = call i32 @exit(i32 -1)
unreachable
51: ; preds = %33
%52 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@.str = [12 x i8] c"/usr/bin/%s\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 = [25 x i8] c"%s/Contents/MacOS/%s $@\0A\00"
@.str.4 = [45 x i8] c"Unexpected I/O error while writing to \22%s\22!\0A\00"
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@.str.5 = [60 x i8] c"Unexpected I/O error while setting the permssions of \22%s\22!\0A\00"
define void @install(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 ([12 x i8], [12 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 ([25 x i8], [25 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)
%24 = load i32, i32* @S_IRWXU
%25 = load i32, i32* @S_IRGRP
%26 = or i32 %25, %24
%27 = load i32, i32* @S_IXGRP
%28 = or i32 %26, %27
%29 = load i32, i32* @S_IROTH
%30 = or i32 %28, %29
%31 = load i32, i32* @S_IXOTH
%32 = or i32 %30, %31
%33 = call i64 @chmod(i8* %5, i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %22
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%38 = call i32 @exit(i32 -1)
unreachable
39: ; preds = %22
ret void
}