#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
char *dfcaten(char const *, char *);
char *dfcaten3(char const *, char *, char const *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char const *);
int /*<<< orphan*/ free(char *);
scalar_t__ mkdir(char *, int);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
scalar_t__ symlink(char const *, char *);
int /*<<< orphan*/ unlink(char *);
void record_install(const char *relative_path, const char *src_path,
                    const char *dest_path, const char *pkg,
                    const char *version) {
  char *linkpath;
  char *record_dir;
  struct stat sb;
  int status;
  record_dir = dfcaten(dest_path, ".spill");
  status = stat(record_dir, &sb);
  if (status < 0) {
    if (mkdir(record_dir, 0755) < 0) {
      fprintf(stderr,
              "Cannot create %s.\nThe installed version of %s has not been "
              "recorded.\n",
              record_dir, pkg);
      exit(1);
    }
  }
  linkpath = dfcaten3(dest_path, ".spill", pkg);
  unlink(linkpath);
  if (symlink(relative_path ? relative_path : src_path, linkpath) < 0) {
    fprintf(stderr,
            "Cannot create %s.\nThe installed version of %s has not been "
            "recorded.\n",
            linkpath, pkg);
  }
  free(record_dir);
  free(linkpath);
  return;
}


x86 assembly (clang, -O0):
<record_install>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1060 <dfcaten@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1090 <stat@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    121e <record_install+0x8e>
mov    -0x38(%rbp),%rdi
mov    $0x1ed,%esi
call   1050 <mkdir@plt>
cmp    $0x0,%rax
jge    1219 <record_install+0x89>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdfd(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    121e <record_install+0x8e>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdd3(%rip),%rsi
call   10a0 <dfcaten3@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <unlink@plt>
cmpq   $0x0,-0x8(%rbp)
je     1257 <record_install+0xc7>
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    125f <record_install+0xcf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <symlink@plt>
cmp    $0x0,%rax
jge    1293 <record_install+0x103>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xd79(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<record_install>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%r12
lea    0xe52(%rip),%rsi
mov    %rdx,%rdi
call   1060 <dfcaten@plt>
mov    %rax,%r15
mov    %rsp,%rsi
mov    %rax,%rdi
call   1090 <stat@plt>
test   %eax,%eax
jns    11da <record_install+0x4a>
mov    %r15,%rdi
mov    $0x1ed,%esi
call   1050 <mkdir@plt>
test   %rax,%rax
js     1247 <record_install+0xb7>
lea    0xe1f(%rip),%rsi
mov    %r13,%rdi
mov    %r14,%rdx
call   10a0 <dfcaten3@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <unlink@plt>
test   %r12,%r12
cmovne %r12,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <symlink@plt>
test   %rax,%rax
jns    1229 <record_install+0x99>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xde9(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1080 <fprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xdb0(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [7 x i8] c".spill\00"
@stderr = global i32 0
@.str.1 = [70 x i8] c"Cannot create %s.\0AThe installed version of %s has not been recorded.\0A\00"
define void @record_install(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca %struct.stat
%14 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%15 = load i8*, i8** %8
%16 = call i8* @dfcaten(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %12
%17 = load i8*, i8** %12
%18 = call i32 @stat(i8* %17, %struct.stat* %13)
store i32 %18, i32* %14
%19 = load i32, i32* %14
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %5
%22 = load i8*, i8** %12
%23 = call i64 @mkdir(i8* %22, i32 493)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %12
%28 = load i8*, i8** %9
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %21
br label %32
32: ; preds = %31, %5
%33 = load i8*, i8** %8
%34 = load i8*, i8** %9
%35 = call i8* @dfcaten3(i8* %33, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %34)
store i8* %35, i8** %11
%36 = load i8*, i8** %11
%37 = call i32 @unlink(i8* %36)
%38 = load i8*, i8** %6
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %42
40: ; preds = %32
%41 = load i8*, i8** %6
br label %44
42: ; preds = %32
%43 = load i8*, i8** %7
br label %44
44: ; preds = %42, %40
%45 = phi i8* [ %41, %40 ], [ %43, %42 ]
%46 = load i8*, i8** %11
%47 = call i64 @symlink(i8* %45, i8* %46)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %44
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %11
%52 = load i8*, i8** %9
%53 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i8* %51, i8* %52)
br label %54
54: ; preds = %49, %44
%55 = load i8*, i8** %12
%56 = call i32 @free(i8* %55)
%57 = load i8*, i8** %11
%58 = call i32 @free(i8* %57)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [7 x i8] c".spill\00"
@stderr = global i32 0
@.str.1 = [70 x i8] c"Cannot create %s.\0AThe installed version of %s has not been recorded.\0A\00"
define void @record_install(i8* %0, i8* %1, i8* %2, i8* %3, i8* nocapture readnone %4) {
%6 = alloca %struct.stat
%7 = bitcast %struct.stat* %6 to i8*
%8 = tail call i8* @dfcaten(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @stat(i8* %8, %struct.stat* %6)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %5
%12 = tail call i64 @mkdir(i8* %8, i32 493)
%13 = icmp slt i64 %12, 0
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 ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %3)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %11, %5
%19 = tail call i8* @dfcaten3(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %3)
%20 = tail call i32 @unlink(i8* %19)
%21 = icmp eq i8* %0, null
%22 = select i1 %21, i8* %1, i8* %0
%23 = tail call i64 @symlink(i8* %22, i8* %19)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %3)
br label %28
28: ; preds = %25, %18
%29 = tail call i32 @free(i8* %8)
%30 = tail call i32 @free(i8* %19)
ret void
}