#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*/ confpath;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memset(char *, int, int);
scalar_t__ mount_device(char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
char *strdup(char const *);
char *strerror(int /*<<< orphan*/);
char *strsep(char **, char *);
char *read_conf(const char *conf_name) {
  char *ret = NULL;
  printf("Reading config %s\n", conf_name);
  char *work_name = strdup(conf_name);
  char *free_work_name = work_name;
  char *device = NULL, *fstype = NULL, *path = NULL;
  device = strsep(&work_name, ":");
  fstype = strsep(&work_name, ":");
  path = strsep(&work_name, ":");
  if (!(device && fstype && path)) {
    printf("Bad config name.\n");
  } else {
    if (mount_device(device, fstype)) {
      char confpath[421];
      snprintf(confpath, sizeof(confpath), "/tmp/mnt/%s/%s", device, path);
      int fd = open(confpath, O_RDONLY);
      if (fd >= 0) {
        char buffer[1000];
        memset(buffer, 0x0, sizeof(buffer));
        int r = read(fd, buffer, sizeof(buffer) - 1);
        if (r > 0) {
          ret = strdup(buffer);
          printf("Parsed %s\n", confpath);
        } else {
          if (r == 0) {
            printf("Empty file %s\n", confpath);
          } else {
            printf("Problem reading %s: %s\n", confpath, strerror(errno));
          }
        }
        close(fd);
      } else {
        printf("Couldn't open '%s': %s\n", confpath, strerror(errno));
      }
    }
  }
  free(free_work_name);
  return ret;
}


x86 assembly (clang, -O0):
<read_conf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5f0,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
lea    -0x18(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   10a0 <strsep@plt>
mov    %rax,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   10a0 <strsep@plt>
mov    %rax,-0x30(%rbp)
lea    -0x18(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   10a0 <strsep@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1263 <read_conf+0xb3>
cmpq   $0x0,-0x30(%rbp)
je     1263 <read_conf+0xb3>
cmpq   $0x0,-0x38(%rbp)
jne    1276 <read_conf+0xc6>
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13ea <read_conf+0x23a>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <mount_device@plt>
cmp    $0x0,%rax
je     13e5 <read_conf+0x235>
lea    -0x1e0(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    $0x1a5,%esi
lea    0xd7f(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x1e0(%rbp),%rdi
mov    0x2d2d(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x1e4(%rbp)
cmpl   $0x0,-0x1e4(%rbp)
jl     13ac <read_conf+0x1fc>
lea    -0x5d0(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1070 <memset@plt>
mov    -0x1e4(%rbp),%edi
lea    -0x5d0(%rbp),%rsi
mov    $0x3e7,%edx
call   1090 <read@plt>
mov    %eax,-0x5d4(%rbp)
cmpl   $0x0,-0x5d4(%rbp)
jle    133c <read_conf+0x18c>
lea    -0x5d0(%rbp),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x10(%rbp)
lea    -0x1e0(%rbp),%rsi
lea    0xd06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    139c <read_conf+0x1ec>
cmpl   $0x0,-0x5d4(%rbp)
jne    1363 <read_conf+0x1b3>
lea    -0x1e0(%rbp),%rsi
lea    0xcea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1397 <read_conf+0x1e7>
lea    -0x1e0(%rbp),%rax
mov    %rax,-0x5e0(%rbp)
mov    0x2c60(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x5e0(%rbp),%rsi
mov    %rax,%rdx
lea    0xcc0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    139c <read_conf+0x1ec>
mov    -0x1e4(%rbp),%edi
call   1080 <close@plt>
jmp    13e0 <read_conf+0x230>
lea    -0x1e0(%rbp),%rax
mov    %rax,-0x5e8(%rbp)
mov    0x2c17(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x5e8(%rbp),%rsi
mov    %rax,%rdx
lea    0xc8f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13e5 <read_conf+0x235>
jmp    13ea <read_conf+0x23a>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x5f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_conf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x5a8,%rsp
mov    %rdi,%rbx
lea    0xe25(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   10d0 <strdup@plt>
mov    %rax,%r15
mov    %rax,0x8(%rsp)
lea    0xe17(%rip),%rbp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10b0 <strsep@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10b0 <strsep@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10b0 <strsep@plt>
test   %r12,%r12
je     12e1 <read_conf+0x121>
test   %r13,%r13
je     12e1 <read_conf+0x121>
mov    %rax,%r14
test   %rax,%rax
je     12e1 <read_conf+0x121>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <mount_device@plt>
test   %rax,%rax
je     12ed <read_conf+0x12d>
lea    0xdb4(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1a5,%esi
mov    %r12,%rcx
mov    %r14,%r8
call   1070 <snprintf@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     12f1 <read_conf+0x131>
mov    %eax,%r14d
lea    0x1c0(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1080 <memset@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x3e7,%edx
call   10a0 <read@plt>
test   %eax,%eax
jle    1319 <read_conf+0x159>
lea    0x1c0(%rsp),%rdi
call   10d0 <strdup@plt>
mov    %rax,%rbp
lea    0xd51(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1341 <read_conf+0x181>
lea    0xd86(%rip),%rdi
call   1040 <puts@plt>
xor    %ebp,%ebp
jmp    1349 <read_conf+0x189>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xd50(%rip),%rdi
xor    %ebp,%ebp
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1349 <read_conf+0x189>
je     1366 <read_conf+0x1a6>
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xd0e(%rip),%rdi
xor    %ebp,%ebp
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
call   1090 <close@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x5a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcc2(%rip),%rdi
xor    %ebp,%ebp
jmp    12d3 <read_conf+0x113>

LLVM IR (-O0):
@.str = [19 x i8] c"Reading config %s\0A\00"
@.str.1 = [2 x i8] c":\00"
@.str.2 = [18 x i8] c"Bad config name.\0A\00"
@.str.3 = [15 x i8] c"/tmp/mnt/%s/%s\00"
@O_RDONLY = global i32 0
@.str.4 = [11 x i8] c"Parsed %s\0A\00"
@.str.5 = [15 x i8] c"Empty file %s\0A\00"
@.str.6 = [24 x i8] c"Problem reading %s: %s\0A\00"
@errno = global i32 0
@.str.7 = [24 x i8] c"Couldn't open '%s': %s\0A\00"
define i8* @read_conf(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [421 x i8]
%10 = alloca i32
%11 = alloca [1000 x i8]
%12 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %3
%13 = load i8*, i8** %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %2
%16 = call i8* @strdup(i8* %15)
store i8* %16, i8** %4
%17 = load i8*, i8** %4
store i8* %17, i8** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
%18 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %18, i8** %6
%19 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %19, i8** %7
%20 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %20, i8** %8
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %29
23: ; preds = %1
%24 = load i8*, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i8*, i8** %8
%28 = icmp ne i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %26, %23, %1
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %81
31: ; preds = %26
%32 = load i8*, i8** %6
%33 = load i8*, i8** %7
%34 = call i64 @mount_device(i8* %32, i8* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %80
36: ; preds = %31
%37 = getelementptr inbounds [421 x i8], [421 x i8]* %9, i64 0, i64 0
%38 = load i8*, i8** %6
%39 = load i8*, i8** %8
%40 = call i32 @snprintf(i8* %37, i32 421, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %38, i8* %39)
%41 = getelementptr inbounds [421 x i8], [421 x i8]* %9, i64 0, i64 0
%42 = load i32, i32* @O_RDONLY
%43 = call i32 @open(i8* %41, i32 %42)
store i32 %43, i32* %10
%44 = load i32, i32* %10
%45 = icmp sge i32 %44, 0
br i1 %45, label %46, label %74
46: ; preds = %36
%47 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%48 = call i32 @memset(i8* %47, i32 0, i32 1000)
%49 = load i32, i32* %10
%50 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%51 = call i32 @read(i32 %49, i8* %50, i32 999)
store i32 %51, i32* %12
%52 = load i32, i32* %12
%53 = icmp sgt i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %46
%55 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%56 = call i8* @strdup(i8* %55)
store i8* %56, i8** %3
%57 = getelementptr inbounds [421 x i8], [421 x i8]* %9, i64 0, i64 0
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %57)
br label %71
59: ; preds = %46
%60 = load i32, i32* %12
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = getelementptr inbounds [421 x i8], [421 x i8]* %9, i64 0, i64 0
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %63)
br label %70
65: ; preds = %59
%66 = getelementptr inbounds [421 x i8], [421 x i8]* %9, i64 0, i64 0
%67 = load i32, i32* @errno
%68 = call i8* @strerror(i32 %67)
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %66, i8* %68)
br label %70
70: ; preds = %65, %62
br label %71
71: ; preds = %70, %54
%72 = load i32, i32* %10
%73 = call i32 @close(i32 %72)
br label %79
74: ; preds = %36
%75 = getelementptr inbounds [421 x i8], [421 x i8]* %9, i64 0, i64 0
%76 = load i32, i32* @errno
%77 = call i8* @strerror(i32 %76)
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %75, i8* %77)
br label %79
79: ; preds = %74, %71
br label %80
80: ; preds = %79, %31
br label %81
81: ; preds = %80, %29
%82 = load i8*, i8** %5
%83 = call i32 @free(i8* %82)
%84 = load i8*, i8** %3
ret i8* %84
}

LLVM IR (-O2):
@.str = [19 x i8] c"Reading config %s\0A\00"
@.str.1 = [2 x i8] c":\00"
@.str.3 = [15 x i8] c"/tmp/mnt/%s/%s\00"
@O_RDONLY = global i32 0
@.str.4 = [11 x i8] c"Parsed %s\0A\00"
@.str.5 = [15 x i8] c"Empty file %s\0A\00"
@.str.6 = [24 x i8] c"Problem reading %s: %s\0A\00"
@errno = global i32 0
@.str.7 = [24 x i8] c"Couldn't open '%s': %s\0A\00"
@str = [17 x i8] c"Bad config name.\00"
define noalias i8* @read_conf(i8* %0) {
%2 = alloca i8*
%3 = alloca [421 x i8]
%4 = alloca [1000 x i8]
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = bitcast i8** %2 to i8*
%7 = tail call i8* @strdup(i8* %0)
store i8* %7, i8** %2
%8 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp ne i8* %8, null
%12 = icmp ne i8* %9, null
%13 = select i1 %11, i1 %12, i1 false
%14 = icmp ne i8* %10, null
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %18, label %16
16: ; preds = %1
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %52
18: ; preds = %1
%19 = call i64 @mount_device(i8* %8, i8* %9)
%20 = icmp eq i64 %19, 0
br i1 %20, label %52, label %21
21: ; preds = %18
%22 = getelementptr inbounds [421 x i8], [421 x i8]* %3, i64 0, i64 0
%23 = call i32 @snprintf(i8* %22, i32 421, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %8, i8* %10)
%24 = load i32, i32* @O_RDONLY
%25 = call i32 @open(i8* %22, i32 %24)
%26 = icmp sgt i32 %25, -1
br i1 %26, label %27, label %46
27: ; preds = %21
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%29 = call i32 @memset(i8* %28, i32 0, i32 1000)
%30 = call i32 @read(i32 %25, i8* %28, i32 999)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i8* @strdup(i8* %28)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %22)
br label %43
35: ; preds = %27
%36 = icmp eq i32 %30, 0
br i1 %36, label %37, label %39
37: ; preds = %35
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %22)
br label %43
39: ; preds = %35
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %22, i8* %41)
br label %43
43: ; preds = %37, %39, %32
%44 = phi i8* [ %33, %32 ], [ null, %37 ], [ null, %39 ]
%45 = call i32 @close(i32 %25)
br label %50
46: ; preds = %21
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %22, i8* %48)
br label %50
50: ; preds = %46, %43
%51 = phi i8* [ %44, %43 ], [ null, %46 ]
br label %52
52: ; preds = %18, %50, %16
%53 = phi i8* [ %51, %50 ], [ null, %18 ], [ null, %16 ]
%54 = call i32 @free(i8* %7)
ret i8* %53
}