#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 */
char *encode_label(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
char *getenv(char *);
char *join_paths(char *, char *);
int /*<<< orphan*/ mkdir_recursive(char *);
int /*<<< orphan*/ mountpoint_for_device(char const *);
int /*<<< orphan*/ pb_log(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
scalar_t__ symlink(int /*<<< orphan*/, char *);
int /*<<< orphan*/ unlink(char *);
void setup_device_links(const char *device) {
  struct link {
    char *env, *dir;
  } * link, links[] = {{.env = "ID_FS_UUID", .dir = "disk/by-uuid"},
                       {.env = "ID_FS_LABEL", .dir = "disk/by-label"},
                       {.env = NULL}};
  for (link = links; link->env; link++) {
    char *value, *dir, *path;
    value = getenv(link->env);
    if (!value)
      continue;
    value = encode_label(value);
    dir = join_paths("/var/tmp/mnt/", link->dir);
    path = join_paths(dir, value);
    if (!mkdir_recursive(dir)) {
      unlink(path);
      if (symlink(mountpoint_for_device(device), path)) {
        pb_log("symlink(%s): %s\n", path, strerror(errno));
      }
    }
    free(path);
    free(dir);
    free(value);
  }
}


x86 assembly (clang, -O0):
<setup_device_links>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1090 <memset@plt>
lea    0xe2d(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe2d(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe2f(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe30(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     12f6 <setup_device_links+0x146>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    122e <setup_device_links+0x7e>
jmp    12e5 <setup_device_links+0x135>
mov    -0x48(%rbp),%rdi
call   1080 <encode_label@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xde8(%rip),%rdi
call   10c0 <join_paths@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   10c0 <join_paths@plt>
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
call   10d0 <mkdir_recursive@plt>
cmp    $0x0,%eax
jne    12ca <setup_device_links+0x11a>
mov    -0x58(%rbp),%rdi
call   1050 <unlink@plt>
mov    -0x8(%rbp),%rdi
call   10a0 <mountpoint_for_device@plt>
mov    %eax,%edi
mov    -0x58(%rbp),%rsi
call   1070 <symlink@plt>
cmp    $0x0,%rax
je     12c5 <setup_device_links+0x115>
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
lea    0xd80(%rip),%rdi
call   1060 <pb_log@plt>
jmp    12ca <setup_device_links+0x11a>
mov    -0x58(%rbp),%rdi
call   1040 <free@plt>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x48(%rbp),%rdi
call   1040 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
jmp    1200 <setup_device_links+0x50>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_device_links>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xe40(%rip),%rdi
mov    %rdi,(%rsp)
lea    0xe40(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0x10(%rsp),%r15
lea    0xe3c(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe3c(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe3e(%rip),%r12
jmp    1228 <setup_device_links+0x88>
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r13,%rdi
call   1040 <free@plt>
mov    (%r15),%rdi
add    $0x10,%r15
test   %rdi,%rdi
je     12ad <setup_device_links+0x10d>
call   1030 <getenv@plt>
test   %rax,%rax
je     1218 <setup_device_links+0x78>
mov    %rax,%rdi
call   1080 <encode_label@plt>
mov    %rax,%r13
mov    -0x8(%r15),%rsi
mov    %r12,%rdi
call   10b0 <join_paths@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
call   10b0 <join_paths@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   10c0 <mkdir_recursive@plt>
test   %eax,%eax
jne    1200 <setup_device_links+0x60>
mov    %rbp,%rdi
call   1050 <unlink@plt>
mov    %r14,%rdi
call   1090 <mountpoint_for_device@plt>
mov    %eax,%edi
mov    %rbp,%rsi
call   1070 <symlink@plt>
test   %rax,%rax
je     1200 <setup_device_links+0x60>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xda2(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1060 <pb_log@plt>
jmp    1200 <setup_device_links+0x60>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.link = type { i8*, i8* }
@.str = [11 x i8] c"ID_FS_UUID\00"
@.str.1 = [13 x i8] c"disk/by-uuid\00"
@.str.2 = [12 x i8] c"ID_FS_LABEL\00"
@.str.3 = [14 x i8] c"disk/by-label\00"
@.str.4 = [14 x i8] c"/var/tmp/mnt/\00"
@.str.5 = [17 x i8] c"symlink(%s): %s\0A\00"
@errno = global i32 0
define void @setup_device_links(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.link*
%4 = alloca [3 x %struct.link]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %2
%8 = bitcast [3 x %struct.link]* %4 to i8*
%9 = bitcast i8* %8 to [3 x %struct.link]*
%10 = getelementptr inbounds [3 x %struct.link], [3 x %struct.link]* %9, i32 0, i32 0
%11 = getelementptr inbounds %struct.link, %struct.link* %10, i32 0, i32 0
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds %struct.link, %struct.link* %10, i32 0, i32 1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [3 x %struct.link], [3 x %struct.link]* %9, i32 0, i32 1
%14 = getelementptr inbounds %struct.link, %struct.link* %13, i32 0, i32 0
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0), i8** %14
%15 = getelementptr inbounds %struct.link, %struct.link* %13, i32 0, i32 1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i32 0, i32 0), i8** %15
%16 = getelementptr inbounds [3 x %struct.link], [3 x %struct.link]* %4, i64 0, i64 0
store %struct.link* %16, %struct.link** %3
br label %17
17: ; preds = %64, %1
%18 = load %struct.link*, %struct.link** %3
%19 = getelementptr inbounds %struct.link, %struct.link* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %67
22: ; preds = %17
%23 = load %struct.link*, %struct.link** %3
%24 = getelementptr inbounds %struct.link, %struct.link* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i8* @getenv(i8* %25)
store i8* %26, i8** %5
%27 = load i8*, i8** %5
%28 = icmp ne i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %22
br label %64
30: ; preds = %22
%31 = load i8*, i8** %5
%32 = call i8* @encode_label(i8* %31)
store i8* %32, i8** %5
%33 = load %struct.link*, %struct.link** %3
%34 = getelementptr inbounds %struct.link, %struct.link* %33, i32 0, i32 1
%35 = load i8*, i8** %34
%36 = call i8* @join_paths(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %35)
store i8* %36, i8** %6
%37 = load i8*, i8** %6
%38 = load i8*, i8** %5
%39 = call i8* @join_paths(i8* %37, i8* %38)
store i8* %39, i8** %7
%40 = load i8*, i8** %6
%41 = call i32 @mkdir_recursive(i8* %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %57, label %43
43: ; preds = %30
%44 = load i8*, i8** %7
%45 = call i32 @unlink(i8* %44)
%46 = load i8*, i8** %2
%47 = call i32 @mountpoint_for_device(i8* %46)
%48 = load i8*, i8** %7
%49 = call i64 @symlink(i32 %47, i8* %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %43
%52 = load i8*, i8** %7
%53 = load i32, i32* @errno
%54 = call i32 @strerror(i32 %53)
%55 = call i32 @pb_log(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %52, i32 %54)
br label %56
56: ; preds = %51, %43
br label %57
57: ; preds = %56, %30
%58 = load i8*, i8** %7
%59 = call i32 @free(i8* %58)
%60 = load i8*, i8** %6
%61 = call i32 @free(i8* %60)
%62 = load i8*, i8** %5
%63 = call i32 @free(i8* %62)
br label %64
64: ; preds = %57, %29
%65 = load %struct.link*, %struct.link** %3
%66 = getelementptr inbounds %struct.link, %struct.link* %65, i32 1
store %struct.link* %66, %struct.link** %3
br label %17
67: ; preds = %17
ret void
}

LLVM IR (-O2):
%struct.link = type { i8*, i8* }
@.str = [11 x i8] c"ID_FS_UUID\00"
@.str.1 = [13 x i8] c"disk/by-uuid\00"
@.str.2 = [12 x i8] c"ID_FS_LABEL\00"
@.str.3 = [14 x i8] c"disk/by-label\00"
@.str.4 = [14 x i8] c"/var/tmp/mnt/\00"
@.str.5 = [17 x i8] c"symlink(%s): %s\0A\00"
@errno = global i32 0
define void @setup_device_links(i8* %0) {
%2 = alloca [3 x %struct.link]
%3 = bitcast [3 x %struct.link]* %2 to i8*
%4 = getelementptr inbounds [3 x %struct.link], [3 x %struct.link]* %2, i64 0, i64 2
%5 = bitcast %struct.link* %4 to i8*
%6 = getelementptr inbounds [3 x %struct.link], [3 x %struct.link]* %2, i64 0, i64 0, i32 0
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [3 x %struct.link], [3 x %struct.link]* %2, i64 0, i64 0, i32 1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [3 x %struct.link], [3 x %struct.link]* %2, i64 0, i64 1, i32 0
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [3 x %struct.link], [3 x %struct.link]* %2, i64 0, i64 1, i32 1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [3 x %struct.link], [3 x %struct.link]* %2, i64 0, i64 0
br label %11
11: ; preds = %1, %37
%12 = phi i8* [ %40, %37 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %1 ]
%13 = phi %struct.link* [ %38, %37 ], [ %10, %1 ]
%14 = tail call i8* @getenv(i8* %12)
%15 = icmp eq i8* %14, null
br i1 %15, label %37, label %16
16: ; preds = %11
%17 = tail call i8* @encode_label(i8* %14)
%18 = getelementptr inbounds %struct.link, %struct.link* %13, i64 0, i32 1
%19 = load i8*, i8** %18
%20 = tail call i8* @join_paths(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%21 = tail call i8* @join_paths(i8* %20, i8* %17)
%22 = tail call i32 @mkdir_recursive(i8* %20)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %16
%25 = tail call i32 @unlink(i8* %21)
%26 = tail call i32 @mountpoint_for_device(i8* %0)
%27 = tail call i64 @symlink(i32 %26, i8* %21)
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %24
%30 = load i32, i32* @errno
%31 = tail call i32 @strerror(i32 %30)
%32 = tail call i32 @pb_log(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %21, i32 %31)
br label %33
33: ; preds = %24, %29, %16
%34 = tail call i32 @free(i8* %21)
%35 = tail call i32 @free(i8* %20)
%36 = tail call i32 @free(i8* %17)
br label %37
37: ; preds = %11, %33
%38 = getelementptr inbounds %struct.link, %struct.link* %13, i64 1
%39 = getelementptr inbounds %struct.link, %struct.link* %38, i64 0, i32 0
%40 = load i8*, i8** %39
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %11
42: ; preds = %37
ret void
}