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

/* Variables and functions */
scalar_t__ calloc(scalar_t__, int);
char *getenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strlen(char *);
char *Get_Campaign_Filename() {
  char *full_filename;
  char *home_dir;
  home_dir = getenv("HOME");
  if (!home_dir)
    return NULL;
  full_filename = (char *)calloc(strlen(home_dir) + 64, sizeof(char));
  if (!full_filename)
    return NULL;
  sprintf(full_filename, "%s/.SearchAndRescue/campaign.mis", home_dir);
  return full_filename;
}


x86 assembly (clang, -O0):
<Get_Campaign_Filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1170 <Get_Campaign_Filename+0x30>
movq   $0x0,-0x8(%rbp)
jmp    11c2 <Get_Campaign_Filename+0x82>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x40,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a6 <Get_Campaign_Filename+0x66>
movq   $0x0,-0x8(%rbp)
jmp    11c2 <Get_Campaign_Filename+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe50(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Get_Campaign_Filename>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     118a <Get_Campaign_Filename+0x4a>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x40(%rax),%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     118a <Get_Campaign_Filename+0x4a>
mov    %rax,%rbx
lea    0xe88(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1060 <sprintf@plt>
jmp    118c <Get_Campaign_Filename+0x4c>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [33 x i8] c"%s/.SearchAndRescue/campaign.mis\00"
define i8* @Get_Campaign_Filename() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
store i8* null, i8** %1
br label %22
8: ; preds = %0
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %10, 64
%12 = call i64 @calloc(i64 %11, i32 1)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %2
%14 = load i8*, i8** %2
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %8
store i8* null, i8** %1
br label %22
17: ; preds = %8
%18 = load i8*, i8** %2
%19 = load i8*, i8** %3
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %2
store i8* %21, i8** %1
br label %22
22: ; preds = %17, %16, %7
%23 = load i8*, i8** %1
ret i8* %23
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [33 x i8] c"%s/.SearchAndRescue/campaign.mis\00"
define i8* @Get_Campaign_Filename() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %11, label %3
3: ; preds = %0
%4 = tail call i64 @strlen(i8* %1)
%5 = add nsw i64 %4, 64
%6 = tail call i64 @calloc(i64 %5, i32 1)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = tail call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %11
11: ; preds = %3, %0, %9
%12 = phi i8* [ %7, %9 ], [ null, %0 ], [ null, %3 ]
ret i8* %12
}