#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 */

/* Variables and functions */
int /*<<< orphan*/ basename(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ free(char *);
char *mkdtemp(char *);
int /*<<< orphan*/ rmdir(char *);
char *safe_asprintf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int systemp(char *, char *, char *);
char *mount_path_mount(char *in_path) {
  char *out_path, *str;
  int ret;
  str = safe_asprintf("/tmp/kernel-install-%s-XXXXXX", basename(in_path));
  out_path = mkdtemp(str);
  if (!out_path) {
    fprintf(stderr, "unable to create temporary directory: %s\n",
            strerror(errno));
    free(str);
    return NULL;
  }
  ret = systemp("mount %s %s", in_path, out_path);
  if (ret) {
    fprintf(stderr, "failed to mount %s: %s\n", in_path, strerror(errno));
    rmdir(out_path);
    free(out_path);
    return NULL;
  }
  return out_path;
}


x86 assembly (clang, -O0):
<mount_path_mount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <basename@plt>
mov    %eax,%esi
lea    0xe62(%rip),%rdi
call   1090 <safe_asprintf@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <mkdtemp@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1203 <mount_path_mount+0x83>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1285 <mount_path_mount+0x105>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe36(%rip),%rdi
call   1070 <systemp@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     127d <mount_path_mount+0xfd>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <rmdir@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1285 <mount_path_mount+0x105>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mount_path_mount>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1060 <basename@plt>
lea    0xe6a(%rip),%rdi
mov    %eax,%esi
call   1090 <safe_asprintf@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1080 <mkdtemp@plt>
test   %rax,%rax
je     1207 <mount_path_mount+0x87>
mov    %rax,%rbx
lea    0xe91(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1070 <systemp@plt>
test   %eax,%eax
je     123b <mount_path_mount+0xbb>
mov    0x2e13(%rip),%rax
mov    (%rax),%ebp
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe70(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <rmdir@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
jmp    123b <mount_path_mount+0xbb>
mov    0x2dd2(%rip),%rax
mov    (%rax),%ebp
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdf9(%rip),%rsi
xor    %ebx,%ebx
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"/tmp/kernel-install-%s-XXXXXX\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"unable to create temporary directory: %s\0A\00"
@errno = global i32 0
@.str.2 = [12 x i8] c"mount %s %s\00"
@.str.3 = [24 x i8] c"failed to mount %s: %s\0A\00"
define i8* @mount_path_mount(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @basename(i8* %7)
%9 = call i8* @safe_asprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %8)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = call i8* @mkdtemp(i8* %10)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %21, label %14
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %5
%20 = call i32 @free(i8* %19)
store i8* null, i8** %2
br label %39
21: ; preds = %1
%22 = load i8*, i8** %3
%23 = load i8*, i8** %4
%24 = call i32 @systemp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %22, i8* %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %3
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %29, i8* %31)
%33 = load i8*, i8** %4
%34 = call i32 @rmdir(i8* %33)
%35 = load i8*, i8** %4
%36 = call i32 @free(i8* %35)
store i8* null, i8** %2
br label %39
37: ; preds = %21
%38 = load i8*, i8** %4
store i8* %38, i8** %2
br label %39
39: ; preds = %37, %27, %14
%40 = load i8*, i8** %2
ret i8* %40
}

LLVM IR (-O2):
@.str = [30 x i8] c"/tmp/kernel-install-%s-XXXXXX\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"unable to create temporary directory: %s\0A\00"
@errno = global i32 0
@.str.2 = [12 x i8] c"mount %s %s\00"
@.str.3 = [24 x i8] c"failed to mount %s: %s\0A\00"
define i8* @mount_path_mount(i8* %0) {
%2 = tail call i32 @basename(i8* %0)
%3 = tail call i8* @safe_asprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = tail call i8* @mkdtemp(i8* %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %12
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = tail call i32 @free(i8* %3)
br label %22
12: ; preds = %1
%13 = tail call i32 @systemp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %4)
%14 = icmp eq i32 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %18)
%20 = tail call i32 @rmdir(i8* %4)
%21 = tail call i32 @free(i8* %4)
br label %22
22: ; preds = %12, %15, %6
%23 = phi i8* [ null, %15 ], [ null, %6 ], [ %4, %12 ]
ret i8* %23
}