#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*/ hostname;
typedef int /*<<< orphan*/ fname;
typedef int /*<<< orphan*/ ext;
typedef int /*<<< orphan*/ dir;

/* Variables and functions */
int /*<<< orphan*/ backslash(char *);
scalar_t__ fexistcase(char *);
char *getfext(char *);
scalar_t__ gethostname(char *, int);
int /*<<< orphan*/ safe_snprintf(char *, size_t, char *, char *, char *, char *,
                                 ...);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *iniFileName(char *dest, size_t maxlen, const char *indir,
                  const char *infname) {
  char dir[260 + 1];
  char fname[260 + 1];
  char ext[260 + 1];
  char *p;
  (strncpy(dir, indir, sizeof(dir)), dir[sizeof(dir) - 1] = 0);
  backslash(dir);
  (strncpy(fname, infname, sizeof(fname)), fname[sizeof(fname) - 1] = 0);
  ext[0] = 0;
  if ((p = getfext(fname)) != NULL) {
    (strncpy(ext, p, sizeof(ext)), ext[sizeof(ext) - 1] = 0);
    *p = 0;
  }
  {
    char hostname[128];
    if (gethostname(hostname, sizeof(hostname)) == 0) {
      safe_snprintf(dest, maxlen, "%s%s.%s%s", dir, fname, hostname, ext);
      if (fexistcase(dest))
        return (dest);
      if ((p = strchr(hostname, '.')) != NULL) {
        *p = 0;
        safe_snprintf(dest, maxlen, "%s%s.%s%s", dir, fname, hostname, ext);
        if (fexistcase(dest))
          return (dest);
      }
    }
  }
  safe_snprintf(dest, maxlen, "%s%s.%s%s", dir, fname, "Linux", ext);
  if (fexistcase(dest))
    return (dest);
  safe_snprintf(dest, maxlen, "%s%s%s", dir, fname, ext);
  fexistcase(dest);
  return (dest);
}


x86 assembly (clang, -O0):
<iniFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3f0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x105,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x2c(%rbp)
lea    -0x130(%rbp),%rdi
call   1090 <backslash@plt>
lea    -0x240(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x105,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x13c(%rbp)
movb   $0x0,-0x350(%rbp)
lea    -0x240(%rbp),%rdi
call   1070 <getfext@plt>
mov    %rax,-0x358(%rbp)
cmp    $0x0,%rax
je     1219 <iniFileName+0xa9>
lea    -0x350(%rbp),%rdi
mov    -0x358(%rbp),%rsi
mov    $0x105,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x24c(%rbp)
mov    -0x358(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x3e0(%rbp),%rdi
mov    $0x80,%esi
call   1080 <gethostname@plt>
cmp    $0x0,%rax
jne    1316 <iniFileName+0x1a6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x130(%rbp),%rcx
lea    -0x240(%rbp),%r8
lea    -0x3e0(%rbp),%r9
lea    -0x350(%rbp),%rax
lea    0xda1(%rip),%rdx
mov    %rax,(%rsp)
mov    $0x0,%al
call   1060 <safe_snprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fexistcase@plt>
cmp    $0x0,%rax
je     128a <iniFileName+0x11a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13a8 <iniFileName+0x238>
lea    -0x3e0(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x358(%rbp)
cmp    $0x0,%rax
je     1311 <iniFileName+0x1a1>
mov    -0x358(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x130(%rbp),%rcx
lea    -0x240(%rbp),%r8
lea    -0x3e0(%rbp),%r9
lea    -0x350(%rbp),%rax
lea    0xd1f(%rip),%rdx
mov    %rax,(%rsp)
mov    $0x0,%al
call   1060 <safe_snprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fexistcase@plt>
cmp    $0x0,%rax
je     130c <iniFileName+0x19c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13a8 <iniFileName+0x238>
jmp    1311 <iniFileName+0x1a1>
jmp    1316 <iniFileName+0x1a6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x130(%rbp),%rcx
lea    -0x240(%rbp),%r8
lea    -0x350(%rbp),%rax
lea    0xcc6(%rip),%rdx
lea    0xcc9(%rip),%r9
mov    %rax,(%rsp)
mov    $0x0,%al
call   1060 <safe_snprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fexistcase@plt>
cmp    $0x0,%rax
je     136c <iniFileName+0x1fc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13a8 <iniFileName+0x238>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x130(%rbp),%rcx
lea    -0x240(%rbp),%r8
lea    -0x350(%rbp),%r9
lea    0xc80(%rip),%rdx
mov    $0x0,%al
call   1060 <safe_snprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fexistcase@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x3f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iniFileName>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3b8,%rsp
mov    %rcx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x2b0(%rsp),%r12
mov    %r12,%rdi
mov    %rdx,%rsi
mov    $0x105,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x3b4(%rsp)
mov    %r12,%rdi
call   1090 <backslash@plt>
lea    0x1a0(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x105,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x2a4(%rsp)
movb   $0x0,0x90(%rsp)
mov    %r12,%rdi
call   1070 <getfext@plt>
test   %rax,%rax
je     1207 <iniFileName+0x97>
mov    %rax,%rbx
lea    0x90(%rsp),%rdi
mov    %rax,%rsi
mov    $0x105,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x194(%rsp)
movb   $0x0,(%rbx)
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
call   1080 <gethostname@plt>
test   %rax,%rax
je     1295 <iniFileName+0x125>
lea    0x90(%rsp),%rax
mov    %rax,(%rsp)
lea    0xdd2(%rip),%rdx
lea    0xdd5(%rip),%r9
lea    0x2b0(%rsp),%rcx
lea    0x1a0(%rsp),%r8
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <safe_snprintf@plt>
mov    %r15,%rdi
call   1050 <fexistcase@plt>
test   %rax,%rax
jne    12d7 <iniFileName+0x167>
lea    0xdaa(%rip),%rdx
lea    0x2b0(%rsp),%rcx
lea    0x1a0(%rsp),%r8
lea    0x90(%rsp),%r9
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <safe_snprintf@plt>
mov    %r15,%rdi
call   1050 <fexistcase@plt>
jmp    12d7 <iniFileName+0x167>
lea    0x90(%rsp),%rbx
mov    %rbx,(%rsp)
lea    0xd58(%rip),%rdx
lea    0x2b0(%rsp),%rcx
lea    0x1a0(%rsp),%r8
lea    0x10(%rsp),%r9
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <safe_snprintf@plt>
mov    %r15,%rdi
call   1050 <fexistcase@plt>
test   %rax,%rax
je     12e9 <iniFileName+0x179>
mov    %r15,%rax
add    $0x3b8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0x10(%rsp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     121b <iniFileName+0xab>
movb   $0x0,(%rax)
mov    %rbx,(%rsp)
lea    0xcf1(%rip),%rdx
lea    0x2b0(%rsp),%rcx
lea    0x1a0(%rsp),%r8
lea    0x10(%rsp),%r9
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <safe_snprintf@plt>
mov    %r15,%rdi
call   1050 <fexistcase@plt>
test   %rax,%rax
jne    12d7 <iniFileName+0x167>
jmp    121b <iniFileName+0xab>

LLVM IR (-O0):
@.str = [10 x i8] c"%s%s.%s%s\00"
@.str.1 = [6 x i8] c"Linux\00"
@.str.2 = [7 x i8] c"%s%s%s\00"
define i8* @iniFileName(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [261 x i8]
%11 = alloca [261 x i8]
%12 = alloca [261 x i8]
%13 = alloca i8*
%14 = alloca [128 x i8]
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%15 = getelementptr inbounds [261 x i8], [261 x i8]* %10, i64 0, i64 0
%16 = load i8*, i8** %8
%17 = call i32 @strncpy(i8* %15, i8* %16, i32 261)
%18 = getelementptr inbounds [261 x i8], [261 x i8]* %10, i64 0, i64 260
store i8 0, i8* %18
%19 = getelementptr inbounds [261 x i8], [261 x i8]* %10, i64 0, i64 0
%20 = call i32 @backslash(i8* %19)
%21 = getelementptr inbounds [261 x i8], [261 x i8]* %11, i64 0, i64 0
%22 = load i8*, i8** %9
%23 = call i32 @strncpy(i8* %21, i8* %22, i32 261)
%24 = getelementptr inbounds [261 x i8], [261 x i8]* %11, i64 0, i64 260
store i8 0, i8* %24
%25 = getelementptr inbounds [261 x i8], [261 x i8]* %12, i64 0, i64 0
store i8 0, i8* %25
%26 = getelementptr inbounds [261 x i8], [261 x i8]* %11, i64 0, i64 0
%27 = call i8* @getfext(i8* %26)
store i8* %27, i8** %13
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %35
29: ; preds = %4
%30 = getelementptr inbounds [261 x i8], [261 x i8]* %12, i64 0, i64 0
%31 = load i8*, i8** %13
%32 = call i32 @strncpy(i8* %30, i8* %31, i32 261)
%33 = getelementptr inbounds [261 x i8], [261 x i8]* %12, i64 0, i64 260
store i8 0, i8* %33
%34 = load i8*, i8** %13
store i8 0, i8* %34
br label %35
35: ; preds = %29, %4
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%37 = call i64 @gethostname(i8* %36, i32 128)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %72
39: ; preds = %35
%40 = load i8*, i8** %6
%41 = load i64, i64* %7
%42 = getelementptr inbounds [261 x i8], [261 x i8]* %10, i64 0, i64 0
%43 = getelementptr inbounds [261 x i8], [261 x i8]* %11, i64 0, i64 0
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%45 = getelementptr inbounds [261 x i8], [261 x i8]* %12, i64 0, i64 0
%46 = call i32 (i8*, i64, i8*, i8*, i8*, i8*, ...) @safe_snprintf(i8* %40, i64 %41, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %42, i8* %43, i8* %44, i8* %45)
%47 = load i8*, i8** %6
%48 = call i64 @fexistcase(i8* %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %39
%51 = load i8*, i8** %6
store i8* %51, i8** %5
br label %94
52: ; preds = %39
%53 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%54 = call i8* @strchr(i8* %53, i8 signext 46)
store i8* %54, i8** %13
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %71
56: ; preds = %52
%57 = load i8*, i8** %13
store i8 0, i8* %57
%58 = load i8*, i8** %6
%59 = load i64, i64* %7
%60 = getelementptr inbounds [261 x i8], [261 x i8]* %10, i64 0, i64 0
%61 = getelementptr inbounds [261 x i8], [261 x i8]* %11, i64 0, i64 0
%62 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%63 = getelementptr inbounds [261 x i8], [261 x i8]* %12, i64 0, i64 0
%64 = call i32 (i8*, i64, i8*, i8*, i8*, i8*, ...) @safe_snprintf(i8* %58, i64 %59, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %60, i8* %61, i8* %62, i8* %63)
%65 = load i8*, i8** %6
%66 = call i64 @fexistcase(i8* %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %56
%69 = load i8*, i8** %6
store i8* %69, i8** %5
br label %94
70: ; preds = %56
br label %71
71: ; preds = %70, %52
br label %72
72: ; preds = %71, %35
%73 = load i8*, i8** %6
%74 = load i64, i64* %7
%75 = getelementptr inbounds [261 x i8], [261 x i8]* %10, i64 0, i64 0
%76 = getelementptr inbounds [261 x i8], [261 x i8]* %11, i64 0, i64 0
%77 = getelementptr inbounds [261 x i8], [261 x i8]* %12, i64 0, i64 0
%78 = call i32 (i8*, i64, i8*, i8*, i8*, i8*, ...) @safe_snprintf(i8* %73, i64 %74, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %75, i8* %76, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %77)
%79 = load i8*, i8** %6
%80 = call i64 @fexistcase(i8* %79)
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %72
%83 = load i8*, i8** %6
store i8* %83, i8** %5
br label %94
84: ; preds = %72
%85 = load i8*, i8** %6
%86 = load i64, i64* %7
%87 = getelementptr inbounds [261 x i8], [261 x i8]* %10, i64 0, i64 0
%88 = getelementptr inbounds [261 x i8], [261 x i8]* %11, i64 0, i64 0
%89 = getelementptr inbounds [261 x i8], [261 x i8]* %12, i64 0, i64 0
%90 = call i32 (i8*, i64, i8*, i8*, i8*, i8*, ...) @safe_snprintf(i8* %85, i64 %86, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %87, i8* %88, i8* %89)
%91 = load i8*, i8** %6
%92 = call i64 @fexistcase(i8* %91)
%93 = load i8*, i8** %6
store i8* %93, i8** %5
br label %94
94: ; preds = %84, %82, %68, %50
%95 = load i8*, i8** %5
ret i8* %95
}

LLVM IR (-O2):
@.str = [10 x i8] c"%s%s.%s%s\00"
@.str.1 = [6 x i8] c"Linux\00"
@.str.2 = [7 x i8] c"%s%s%s\00"
define i8* @iniFileName(i8* returned %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca [261 x i8]
%6 = alloca [261 x i8]
%7 = alloca [261 x i8]
%8 = alloca [128 x i8]
%9 = getelementptr inbounds [261 x i8], [261 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [261 x i8], [261 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [261 x i8], [261 x i8]* %7, i64 0, i64 0
%12 = call i32 @strncpy(i8* %9, i8* %2, i32 261)
%13 = getelementptr inbounds [261 x i8], [261 x i8]* %5, i64 0, i64 260
store i8 0, i8* %13
%14 = call i32 @backslash(i8* %9)
%15 = call i32 @strncpy(i8* %10, i8* %3, i32 261)
%16 = getelementptr inbounds [261 x i8], [261 x i8]* %6, i64 0, i64 260
store i8 0, i8* %16
store i8 0, i8* %11
%17 = call i8* @getfext(i8* %10)
%18 = icmp eq i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %4
%20 = call i32 @strncpy(i8* %11, i8* %17, i32 261)
%21 = getelementptr inbounds [261 x i8], [261 x i8]* %7, i64 0, i64 260
store i8 0, i8* %21
store i8 0, i8* %17
br label %22
22: ; preds = %19, %4
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%24 = call i64 @gethostname(i8* %23, i32 128)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %38
26: ; preds = %22
%27 = call i32 (i8*, i64, i8*, i8*, i8*, i8*, ...) @safe_snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %10, i8* %23, i8* %11)
%28 = call i64 @fexistcase(i8* %0)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %26
%31 = call i8* @strchr(i8* %23, i8 signext 46)
%32 = icmp eq i8* %31, null
br i1 %32, label %38, label %33
33: ; preds = %30
store i8 0, i8* %31
%34 = call i32 (i8*, i64, i8*, i8*, i8*, i8*, ...) @safe_snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %10, i8* %23, i8* %11)
%35 = call i64 @fexistcase(i8* %0)
%36 = icmp eq i64 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %33, %26
br label %45
38: ; preds = %22, %33, %30
%39 = call i32 (i8*, i64, i8*, i8*, i8*, i8*, ...) @safe_snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%40 = call i64 @fexistcase(i8* %0)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = call i32 (i8*, i64, i8*, i8*, i8*, i8*, ...) @safe_snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* %10, i8* %11)
%44 = call i64 @fexistcase(i8* %0)
br label %45
45: ; preds = %38, %37, %42
ret i8* %0
}