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

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ timlib_file_exists(char *);
FILE *appaserver_parameter_file_open(char *filename, char *application_name) {
  char appaserver_filename[128];
  if (!application_name || !*application_name) {
    sprintf(filename, "%s/%s", "/etc", "appaserver.config");
  } else {
    sprintf(appaserver_filename, "appaserver_%s.config", application_name);
    sprintf(filename, "%s/%s", "/etc", appaserver_filename);
  }
  if (!timlib_file_exists(filename))
    return (FILE *)0;
  else
    return fopen(filename, "r");
}


x86 assembly (clang, -O0):
<appaserver_parameter_file_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     115b <appaserver_parameter_file_open+0x2b>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1180 <appaserver_parameter_file_open+0x50>
mov    -0x10(%rbp),%rdi
lea    0xe9a(%rip),%rsi
lea    0xe99(%rip),%rdx
lea    0xe97(%rip),%rcx
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    11b9 <appaserver_parameter_file_open+0x89>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe8b(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0xa0(%rbp),%rcx
lea    0xe55(%rip),%rsi
lea    0xe54(%rip),%rdx
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <timlib_file_exists@plt>
cmp    $0x0,%eax
jne    11d8 <appaserver_parameter_file_open+0xa8>
movq   $0x0,-0x8(%rbp)
jmp    11ec <appaserver_parameter_file_open+0xbc>
mov    -0x10(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appaserver_parameter_file_open>:
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%rbx
test   %rsi,%rsi
je     1174 <appaserver_parameter_file_open+0x44>
mov    %rsi,%rdx
cmpb   $0x0,(%rsi)
je     1174 <appaserver_parameter_file_open+0x44>
lea    0xecc(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0xe9b(%rip),%rsi
lea    0xe9a(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rcx
jmp    118c <appaserver_parameter_file_open+0x5c>
lea    0xe85(%rip),%rsi
lea    0xe84(%rip),%rdx
lea    0xe82(%rip),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <timlib_file_exists@plt>
test   %eax,%eax
je     11b0 <appaserver_parameter_file_open+0x80>
lea    0xe8c(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
jmp    11b2 <appaserver_parameter_file_open+0x82>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [5 x i8] c"/etc\00"
@.str.2 = [18 x i8] c"appaserver.config\00"
@.str.3 = [21 x i8] c"appaserver_%s.config\00"
@.str.4 = [2 x i8] c"r\00"
define i32* @appaserver_parameter_file_open(i8* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [128 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %9, %2
%14 = load i8*, i8** %4
%15 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %23
16: ; preds = %9
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%18 = load i8*, i8** %5
%19 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %4
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%22 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %16, %13
%24 = load i8*, i8** %4
%25 = call i32 @timlib_file_exists(i8* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %23
store i32* null, i32** %3
br label %31
28: ; preds = %23
%29 = load i8*, i8** %4
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %30, i32** %3
br label %31
31: ; preds = %28, %27
%32 = load i32*, i32** %3
ret i32* %32
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [5 x i8] c"/etc\00"
@.str.2 = [18 x i8] c"appaserver.config\00"
@.str.3 = [21 x i8] c"appaserver_%s.config\00"
@.str.4 = [2 x i8] c"r\00"
define noalias i32* @appaserver_parameter_file_open(i8* %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %1, null
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6, %2
%10 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %14
11: ; preds = %6
%12 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%13 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %14
14: ; preds = %11, %9
%15 = call i32 @timlib_file_exists(i8* %0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %19
19: ; preds = %14, %17
%20 = phi i32* [ %18, %17 ], [ null, %14 ]
ret i32* %20
}