#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 */
int /*<<< orphan*/ equalStrings(char *, char *);
char *realloc(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *addAcodeExtension(char *adventureFileName) {
  if (strlen(adventureFileName) < strlen(".a3c") ||
      !equalStrings(&adventureFileName[strlen(adventureFileName) - 4],
                    ".a3c")) {
    adventureFileName = realloc(adventureFileName,
                                strlen(adventureFileName) + strlen(".a3c") + 1);
    strcat(adventureFileName, ".a3c");
  }
  return adventureFileName;
}


x86 assembly (clang, -O0):
<addAcodeExtension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
lea    0xea1(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
cmp    %ecx,%eax
jl     11a3 <addAcodeExtension+0x63>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x18(%rbp),%rdi
sub    $0x4,%eax
cltq
add    %rax,%rdi
lea    0xe6b(%rip),%rsi
call   1050 <equalStrings@plt>
cmp    $0x0,%eax
jne    11e8 <addAcodeExtension+0xa8>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
lea    0xe42(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdi
add    %eax,%esi
add    $0x1,%esi
call   1040 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addAcodeExtension>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
lea    0xeab(%rip),%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
jl     1180 <addAcodeExtension+0x40>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe89(%rip),%rsi
call   1050 <equalStrings@plt>
test   %eax,%eax
jne    11b5 <addAcodeExtension+0x75>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
lea    0xe6f(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rbp,1),%esi
add    $0x1,%esi
mov    %rbx,%rdi
call   1040 <realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c".a3c\00"
define i8* @addAcodeExtension(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = call i32 @strlen(i8* %3)
%5 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = icmp slt i32 %4, %5
br i1 %6, label %16, label %7
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
%11 = sub nsw i32 %10, 4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %8, i64 %12
%14 = call i32 @equalStrings(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = icmp ne i32 %14, 0
br i1 %15, label %26, label %16
16: ; preds = %7, %1
%17 = load i8*, i8** %2
%18 = load i8*, i8** %2
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = add nsw i32 %19, %20
%22 = add nsw i32 %21, 1
%23 = call i8* @realloc(i8* %17, i32 %22)
store i8* %23, i8** %2
%24 = load i8*, i8** %2
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %16, %7
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
@.str = [5 x i8] c".a3c\00"
define i8* @addAcodeExtension(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp slt i32 %2, %3
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = tail call i32 @strlen(i8* %0)
%7 = add nsw i32 %6, -4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = tail call i32 @equalStrings(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %5, %1
%13 = tail call i32 @strlen(i8* %0)
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = add i32 %13, 1
%16 = add i32 %15, %14
%17 = tail call i8* @realloc(i8* %0, i32 %16)
%18 = tail call i32 @strcat(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %12, %5
%20 = phi i8* [ %17, %12 ], [ %0, %5 ]
ret i8* %20
}