#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 *);
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 default used",
           dist_name);
  } else {
    snprintf(file, len, "%s/%s", dir, "default");
    logger(-1, 0,
           "Warning: distribution not specified"
           " default used %s",
           file);
  }
  if (!stat_file(file)) {
    logger(-1, 0, "Distribution configuration not found %s", 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     12b3 <get_dist_conf_name+0x173>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    0xf15(%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    1327 <get_dist_conf_name+0x1e7>
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    0xd82(%rip),%rdx
lea    0xd81(%rip),%r8
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rcx
mov    $0xffffffff,%edi
xor    %esi,%esi
lea    0xd70(%rip),%rdx
call   1060 <logger@plt>
jmp    12ea <get_dist_conf_name+0x1aa>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    0xd46(%rip),%rdx
lea    0xd45(%rip),%r8
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x20(%rbp),%rcx
mov    $0xffffffff,%edi
xor    %esi,%esi
lea    0xd7b(%rip),%rdx
call   1060 <logger@plt>
mov    -0x20(%rbp),%rdi
call   1050 <stat_file@plt>
cmp    $0x0,%rax
jne    1320 <get_dist_conf_name+0x1e0>
mov    -0x20(%rbp),%rcx
mov    $0xffffffff,%edi
xor    %esi,%esi
lea    0xd85(%rip),%rdx
call   1060 <logger@plt>
movl   $0x6b,-0x4(%rbp)
jmp    1327 <get_dist_conf_name+0x1e7>
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    %ecx,%r15d
mov    %rdx,%r13
mov    %rsi,%rbp
test   %rdi,%rdi
je     123b <get_dist_conf_name+0xfb>
mov    %rdi,%r14
lea    0xf24(%rip),%rdx
xor    %ebx,%ebx
lea    0x20(%rsp),%r12
mov    %r12,%rdi
mov    $0x100,%esi
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,0x1c(%rsp)
lea    0xe67(%rip),%rdx
mov    %r13,%rdi
mov    %r15d,0xc(%rsp)
mov    %r15d,%esi
mov    %rbp,0x10(%rsp)
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    12ce <get_dist_conf_name+0x18e>
movslq 0x1c(%rsp),%rax
lea    (%rsp,%rax,1),%rbp
add    $0x20,%rbp
lea    0xe25(%rip),%r15
xor    %ebx,%ebx
cmp    %r12,%rbp
jbe    12e2 <get_dist_conf_name+0x1a2>
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    126c <get_dist_conf_name+0x12c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x0,0x0(%rbp)
mov    %r13,%rdi
mov    %r15,%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    12ce <get_dist_conf_name+0x18e>
lea    0xdc9(%rip),%rdx
lea    0xdc8(%rip),%r8
mov    %r13,%rdi
mov    %r15d,%esi
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xe00(%rip),%rdx
mov    $0xffffffff,%edi
xor    %esi,%esi
mov    %r13,%rcx
jmp    129f <get_dist_conf_name+0x15f>
mov    0x10(%rsp),%rcx
movb   $0x0,(%r12)
lea    0xd8e(%rip),%rdx
lea    0xd8d(%rip),%r8
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xd84(%rip),%rdx
mov    $0xffffffff,%edi
xor    %esi,%esi
mov    %r14,%rcx
call   1060 <logger@plt>
mov    %r13,%rdi
call   1050 <stat_file@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    12ce <get_dist_conf_name+0x18e>
lea    0xdda(%rip),%rdx
mov    $0xffffffff,%edi
xor    %esi,%esi
mov    %r13,%rcx
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),%rcx
mov    0xc(%rsp),%esi
jmp    1271 <get_dist_conf_name+0x131>

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 = [71 x i8] c"Warning: configuration file for distribution %s not found default used\00"
@.str.5 = [52 x i8] c"Warning: distribution not specified default used %s\00"
@.str.6 = [40 x i8] c"Distribution configuration not found %s\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 %61
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 %76
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 = call i32 @logger(i32 -1, i32 0, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.4, i64 0, i64 0), i8* %59)
br label %68
61: ; preds = %4
%62 = load i8*, i8** %8
%63 = load i32, i32* %9
%64 = load i8*, i8** %7
%65 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %62, i32 %63, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %64, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%66 = load i8*, i8** %8
%67 = call i32 @logger(i32 -1, i32 0, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i8* %66)
br label %68
68: ; preds = %61, %54
%69 = load i8*, i8** %8
%70 = call i64 @stat_file(i8* %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %75, label %72
72: ; preds = %68
%73 = load i8*, i8** %8
%74 = call i32 @logger(i32 -1, i32 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %73)
store i32 107, i32* %5
br label %76
75: ; preds = %68
store i32 0, i32* %5
br label %76
76: ; preds = %75, %72, %32
%77 = load i32, i32* %5
ret i32 %77
}

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 = [71 x i8] c"Warning: configuration file for distribution %s not found default used\00"
@.str.5 = [52 x i8] c"Warning: distribution not specified default used %s\00"
@.str.6 = [40 x i8] c"Distribution configuration not found %s\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 @logger(i32 -1, i32 0, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.4, i64 0, i64 0), i8* %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 @logger(i32 -1, i32 0, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i8* %2)
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 @logger(i32 -1, i32 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), 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
}