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

/* Variables and functions */
int /*<<< orphan*/ logger(int, int /*<<< orphan*/, char *, char *, char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
scalar_t__ stat_file(char *);
int strlen(char *);
int get_dist_conf_name(char *dist_name, char *dir, char *file, int len) {
  char buf[256];
  char *ep;
  if (dist_name != NULL) {
    snprintf(buf, sizeof(buf), "%s", dist_name);
    ep = buf + strlen(buf);
    do {
      snprintf(file, len, "%s/%s.conf", dir, buf);
      if (stat_file(file))
        return 0;
      while (ep > buf && *ep != '-')
        --ep;
      *ep = 0;
    } while (ep > buf);
    snprintf(file, len, "%s/%s", dir, "default");
    logger(-1, 0,
           "Warning: configuration file "
           "for distribution %s not found, "
           "using defaults from %s/%s",
           dist_name, dir, "default");
  } else {
    snprintf(file, len, "%s/%s", dir, "default");
    logger(-1, 0,
           "Warning: distribution not specified "
           "in CT config, "
           "using defaults from %s/%s",
           dir, "default");
  }
  if (!stat_file(file)) {
    logger(-1, 0,
           "Distribution configuration file "
           "%s/%s not found",
           dir, file);
    return 107;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_dist_conf_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     12c0 <get_dist_conf_name+0x180>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    0xee9(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x130(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    -0x130(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x140(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x138(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    -0x130(%rbp),%r8
lea    0xe34(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <stat_file@plt>
cmp    $0x0,%rax
je     11f2 <get_dist_conf_name+0xb2>
movl   $0x0,-0x4(%rbp)
jmp    1343 <get_dist_conf_name+0x203>
jmp    11f7 <get_dist_conf_name+0xb7>
mov    -0x138(%rbp),%rcx
lea    -0x130(%rbp),%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x141(%rbp)
jbe    122c <get_dist_conf_name+0xec>
mov    -0x138(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
setne  %al
mov    %al,-0x141(%rbp)
mov    -0x141(%rbp),%al
test   $0x1,%al
jne    123f <get_dist_conf_name+0xff>
jmp    1256 <get_dist_conf_name+0x116>
mov    -0x138(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x138(%rbp)
jmp    11f7 <get_dist_conf_name+0xb7>
mov    -0x138(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x138(%rbp),%rax
lea    -0x130(%rbp),%rcx
cmp    %rcx,%rax
ja     11b3 <get_dist_conf_name+0x73>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    0xdd9(%rip),%rdx
lea    0xd7b(%rip),%r8
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    $0xffffffff,%edi
xor    %esi,%esi
lea    0xd66(%rip),%rdx
lea    0xd57(%rip),%r9
mov    $0x0,%al
call   1060 <logger@plt>
jmp    1300 <get_dist_conf_name+0x1c0>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    0xd90(%rip),%rdx
lea    0xd32(%rip),%r8
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x18(%rbp),%rcx
mov    $0xffffffff,%edi
xor    %esi,%esi
lea    0xd76(%rip),%rdx
lea    0xd12(%rip),%r8
mov    $0x0,%al
call   1060 <logger@plt>
mov    -0x20(%rbp),%rdi
call   1050 <stat_file@plt>
cmp    $0x0,%rax
jne    133c <get_dist_conf_name+0x1fc>
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    $0xffffffff,%edi
xor    %esi,%esi
lea    0xd8b(%rip),%rdx
mov    $0x0,%al
call   1060 <logger@plt>
movl   $0x6b,-0x4(%rbp)
jmp    1343 <get_dist_conf_name+0x203>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dist_conf_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rdx,%r13
mov    %rsi,%rbp
test   %rdi,%rdi
mov    %rsi,0x10(%rsp)
je     123b <get_dist_conf_name+0xfb>
mov    %rdi,%r15
lea    0xef6(%rip),%rdx
xor    %ebx,%ebx
lea    0x20(%rsp),%r12
mov    %r12,%rdi
mov    $0x100,%esi
mov    %ecx,%r14d
mov    %r15,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,0x1c(%rsp)
lea    0xe62(%rip),%rdx
mov    %r13,%rdi
mov    %r14d,0xc(%rsp)
mov    %r14d,%esi
mov    %rbp,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r13,%rdi
call   1050 <stat_file@plt>
test   %rax,%rax
jne    12ef <get_dist_conf_name+0x1af>
movslq 0x1c(%rsp),%rax
lea    (%rsp,%rax,1),%rbp
add    $0x20,%rbp
lea    0xe25(%rip),%r14
xor    %ebx,%ebx
cmp    %r12,%rbp
jbe    1303 <get_dist_conf_name+0x1c3>
mov    0xc(%rsp),%esi
nopw   0x0(%rax,%rax,1)
cmpb   $0x2d,0x0(%rbp)
je     1210 <get_dist_conf_name+0xd0>
add    $0xffffffffffffffff,%rbp
cmp    %r12,%rbp
ja     11f0 <get_dist_conf_name+0xb0>
jmp    1278 <get_dist_conf_name+0x138>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x0,0x0(%rbp)
mov    %r13,%rdi
mov    %r14,%rdx
mov    0x10(%rsp),%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r13,%rdi
call   1050 <stat_file@plt>
test   %rax,%rax
je     11dd <get_dist_conf_name+0x9d>
jmp    12ef <get_dist_conf_name+0x1af>
lea    0xe20(%rip),%rdx
lea    0xdc2(%rip),%rbx
mov    %r13,%rdi
mov    %ecx,%esi
mov    %rbp,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xe06(%rip),%rdx
mov    $0xffffffff,%edi
xor    %esi,%esi
mov    %rbp,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1060 <logger@plt>
jmp    12be <get_dist_conf_name+0x17e>
mov    0x10(%rsp),%rbp
movb   $0x0,(%r12)
lea    0xdd9(%rip),%rdx
lea    0xd7b(%rip),%rbx
mov    %r13,%rdi
mov    %rbp,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xd6c(%rip),%rdx
mov    $0xffffffff,%edi
xor    %esi,%esi
mov    %r15,%rcx
mov    %rbp,%r8
mov    %rbx,%r9
xor    %eax,%eax
call   1060 <logger@plt>
mov    %r13,%rdi
call   1050 <stat_file@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    12ef <get_dist_conf_name+0x1af>
lea    0xde0(%rip),%rdx
mov    $0xffffffff,%edi
xor    %esi,%esi
mov    0x10(%rsp),%rcx
mov    %r13,%r8
xor    %eax,%eax
call   1060 <logger@plt>
mov    $0x6b,%ebx
mov    %ebx,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%r12
mov    0x10(%rsp),%rbp
mov    0xc(%rsp),%esi
jmp    127d <get_dist_conf_name+0x13d>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [11 x i8] c"%s/%s.conf\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [8 x i8] c"default\00"
@.str.4 = [85 x i8] c"Warning: configuration file for distribution %s not found, using defaults from %s/%s\00"
@.str.5 = [76 x i8] c"Warning: distribution not specified in CT config, using defaults from %s/%s\00"
@.str.6 = [48 x i8] c"Distribution configuration file %s/%s not found\00"
define i32 @get_dist_conf_name(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [256 x i8]
%11 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %62
14: ; preds = %4
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%16 = load i8*, i8** %6
%17 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %15, i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
store i8* %22, i8** %11
br label %23
23: ; preds = %50, %14
%24 = load i8*, i8** %8
%25 = load i32, i32* %9
%26 = load i8*, i8** %7
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%28 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %24, i32 %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %26, i8* %27)
%29 = load i8*, i8** %8
%30 = call i64 @stat_file(i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %23
store i32 0, i32* %5
br label %78
33: ; preds = %23
br label %34
34: ; preds = %45, %33
%35 = load i8*, i8** %11
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%37 = icmp ugt i8* %35, %36
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i8*, i8** %11
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 45
br label %43
43: ; preds = %38, %34
%44 = phi i1 [ false, %34 ], [ %42, %38 ]
br i1 %44, label %45, label %48
45: ; preds = %43
%46 = load i8*, i8** %11
%47 = getelementptr inbounds i8, i8* %46, i32 -1
store i8* %47, i8** %11
br label %34
48: ; preds = %43
%49 = load i8*, i8** %11
store i8 0, i8* %49
br label %50
50: ; preds = %48
%51 = load i8*, i8** %11
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%53 = icmp ugt i8* %51, %52
br i1 %53, label %23, label %54
54: ; preds = %50
%55 = load i8*, i8** %8
%56 = load i32, i32* %9
%57 = load i8*, i8** %7
%58 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %55, i32 %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %57, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%59 = load i8*, i8** %6
%60 = load i8*, i8** %7
%61 = call i32 (i32, i32, i8*, i8*, i8*, ...) @logger(i32 -1, i32 0, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.4, i64 0, i64 0), i8* %59, i8* %60, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %69
62: ; preds = %4
%63 = load i8*, i8** %8
%64 = load i32, i32* %9
%65 = load i8*, i8** %7
%66 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %63, i32 %64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %65, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%67 = load i8*, i8** %7
%68 = call i32 (i32, i32, i8*, i8*, i8*, ...) @logger(i32 -1, i32 0, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.5, i64 0, i64 0), i8* %67, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %62, %54
%70 = load i8*, i8** %8
%71 = call i64 @stat_file(i8* %70)
%72 = icmp ne i64 %71, 0
br i1 %72, label %77, label %73
73: ; preds = %69
%74 = load i8*, i8** %7
%75 = load i8*, i8** %8
%76 = call i32 (i32, i32, i8*, i8*, i8*, ...) @logger(i32 -1, i32 0, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), i8* %74, i8* %75)
store i32 107, i32* %5
br label %78
77: ; preds = %69
store i32 0, i32* %5
br label %78
78: ; preds = %77, %73, %32
%79 = load i32, i32* %5
ret i32 %79
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [11 x i8] c"%s/%s.conf\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [8 x i8] c"default\00"
@.str.4 = [85 x i8] c"Warning: configuration file for distribution %s not found, using defaults from %s/%s\00"
@.str.5 = [76 x i8] c"Warning: distribution not specified in CT config, using defaults from %s/%s\00"
@.str.6 = [48 x i8] c"Distribution configuration file %s/%s not found\00"
define i32 @get_dist_conf_name(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [256 x i8]
%6 = ptrtoint [256 x i8]* %5 to i64
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = icmp eq i8* %0, null
br i1 %8, label %41, label %9
9: ; preds = %4
%10 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %7, i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = call i32 @strlen(i8* %7)
%12 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %7)
%13 = call i64 @stat_file(i8* %2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %49
15: ; preds = %9
%16 = sext i32 %11 to i64
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %16
br label %18
18: ; preds = %15, %28
%19 = phi i8* [ %22, %28 ], [ %17, %15 ]
%20 = icmp ugt i8* %19, %7
br i1 %20, label %21, label %37
21: ; preds = %18, %25
%22 = phi i8* [ %26, %25 ], [ %19, %18 ]
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 45
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = getelementptr inbounds i8, i8* %22, i64 -1
%27 = icmp ugt i8* %26, %7
br i1 %27, label %21, label %32
28: ; preds = %21
store i8 0, i8* %22
%29 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %7)
%30 = call i64 @stat_file(i8* %2)
%31 = icmp eq i64 %30, 0
br i1 %31, label %18, label %49
32: ; preds = %25
%33 = ptrtoint i8* %19 to i64
%34 = getelementptr i8, i8* %19, i64 %6
%35 = sub i64 0, %33
%36 = getelementptr i8, i8* %34, i64 %35
br label %37
37: ; preds = %18, %32
%38 = phi i8* [ %36, %32 ], [ %19, %18 ]
store i8 0, i8* %38
%39 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 (i32, i32, i8*, i8*, i8*, ...) @logger(i32 -1, i32 0, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %44
41: ; preds = %4
%42 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%43 = tail call i32 (i32, i32, i8*, i8*, i8*, ...) @logger(i32 -1, i32 0, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.5, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %41, %37
%45 = call i64 @stat_file(i8* %2)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 (i32, i32, i8*, i8*, i8*, ...) @logger(i32 -1, i32 0, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), i8* %1, i8* %2)
br label %49
49: ; preds = %28, %9, %44, %47
%50 = phi i32 [ 107, %47 ], [ 0, %44 ], [ 0, %9 ], [ 0, %28 ]
ret i32 %50
}