#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__ CG_LoadRecamScriptFile(char *);
int /*<<< orphan*/ CG_Printf(char *);
int /*<<< orphan*/ COM_ReplaceExtension(char *, char *, int);
int /*<<< orphan*/ Q_snprintfz(char *, int, char *, char *);
int strlen(char *);
int trap_Cmd_Argc();
char *trap_Cmd_Argv(int);
char *trap_MemAlloc(int, char *, int);
void CG_Democam_ImportCams_f(void) {
  int name_size;
  char *customName;
  if (trap_Cmd_Argc() < 2) {
    CG_Printf("Usage: importcams <filename> (relative to demos directory)\n");
    return;
  }
  name_size = sizeof(char) * (strlen("demos/") + strlen(trap_Cmd_Argv(1)) +
                              strlen(".cam") + 1);
  customName =
      trap_MemAlloc(name_size,
                    "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/ptitSeb/warsow-pandora/"
                    "refs/heads/master/cgame/cg_democams.c",
                    1682);
  Q_snprintfz(customName, name_size, "demos/%s", trap_Cmd_Argv(1));
  COM_ReplaceExtension(customName, ".cam", name_size);
  if (CG_LoadRecamScriptFile(customName)) {
    CG_Printf("cam script imported\n");
  } else {
    CG_Printf("CG_Democam_ImportCams_f: no valid file found\n");
  }
}


x86 assembly (clang, -O0):
<CG_Democam_ImportCams_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1050 <trap_Cmd_Argc@plt>
cmp    $0x2,%eax
jge    11a9 <CG_Democam_ImportCams_f+0x29>
lea    0xe61(%rip),%rdi
call   1070 <CG_Printf@plt>
jmp    127c <CG_Democam_ImportCams_f+0xfc>
lea    0xe8c(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    $0x1,%edi
call   1090 <trap_Cmd_Argv@plt>
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
lea    0xe68(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    0xe4b(%rip),%rsi
mov    $0x692,%edx
call   10a0 <trap_MemAlloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x1,%edi
call   1090 <trap_Cmd_Argv@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    %rax,%rcx
lea    0xeab(%rip),%rdx
call   1060 <Q_snprintfz@plt>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xdfc(%rip),%rsi
call   1080 <COM_ReplaceExtension@plt>
mov    -0x10(%rbp),%rdi
call   1040 <CG_LoadRecamScriptFile@plt>
cmp    $0x0,%rax
je     1270 <CG_Democam_ImportCams_f+0xf0>
lea    0xe82(%rip),%rdi
call   1070 <CG_Printf@plt>
jmp    127c <CG_Democam_ImportCams_f+0xfc>
lea    0xe86(%rip),%rdi
call   1070 <CG_Printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CG_Democam_ImportCams_f>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <trap_Cmd_Argc@plt>
cmp    $0x2,%eax
jge    119c <CG_Democam_ImportCams_f+0x1c>
lea    0xe69(%rip),%rdi
jmp    1232 <CG_Democam_ImportCams_f+0xb2>
lea    0xe99(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    $0x1,%edi
call   1090 <trap_Cmd_Argv@plt>
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    0xe7e(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %ebp,%ebx
add    %eax,%ebx
add    $0x1,%ebx
lea    0xe6d(%rip),%rsi
mov    %ebx,%edi
mov    $0x692,%edx
call   10a0 <trap_MemAlloc@plt>
mov    %rax,%rbp
mov    $0x1,%edi
call   1090 <trap_Cmd_Argv@plt>
lea    0xee4(%rip),%rdx
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %rax,%rcx
call   1060 <Q_snprintfz@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1080 <COM_ReplaceExtension@plt>
mov    %rbp,%rdi
call   1040 <CG_LoadRecamScriptFile@plt>
test   %rax,%rax
lea    0xed6(%rip),%rax
lea    0xeba(%rip),%rdi
cmove  %rax,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <CG_Printf@plt>

LLVM IR (-O0):
@.str = [60 x i8] c"Usage: importcams <filename> (relative to demos directory)\0A\00"
@.str.1 = [7 x i8] c"demos/\00"
@.str.2 = [5 x i8] c".cam\00"
@.str.3 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ptitSeb/warsow-pandora/refs/heads/master/cgame/cg_democams.c\00"
@.str.4 = [9 x i8] c"demos/%s\00"
@.str.5 = [21 x i8] c"cam script imported\0A\00"
@.str.6 = [46 x i8] c"CG_Democam_ImportCams_f: no valid file found\0A\00"
define void @CG_Democam_ImportCams_f() {
%1 = alloca i32
%2 = alloca i8*
%3 = call i32 (...) @trap_Cmd_Argc()
%4 = icmp slt i32 %3, 2
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @CG_Printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
br label %34
7: ; preds = %0
%8 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%9 = call i8* @trap_Cmd_Argv(i32 1)
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %8, %10
%12 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%13 = add nsw i32 %11, %12
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = mul i64 1, %15
%17 = trunc i64 %16 to i32
store i32 %17, i32* %1
%18 = load i32, i32* %1
%19 = call i8* @trap_MemAlloc(i32 %18, i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.3, i64 0, i64 0), i32 1682)
store i8* %19, i8** %2
%20 = load i8*, i8** %2
%21 = load i32, i32* %1
%22 = call i8* @trap_Cmd_Argv(i32 1)
%23 = call i32 @Q_snprintfz(i8* %20, i32 %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %2
%25 = load i32, i32* %1
%26 = call i32 @COM_ReplaceExtension(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load i8*, i8** %2
%28 = call i64 @CG_LoadRecamScriptFile(i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %7
%31 = call i32 @CG_Printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %34
32: ; preds = %7
%33 = call i32 @CG_Printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
br label %34
34: ; preds = %5, %32, %30
ret void
}

LLVM IR (-O2):
@.str = [60 x i8] c"Usage: importcams <filename> (relative to demos directory)\0A\00"
@.str.1 = [7 x i8] c"demos/\00"
@.str.2 = [5 x i8] c".cam\00"
@.str.3 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ptitSeb/warsow-pandora/refs/heads/master/cgame/cg_democams.c\00"
@.str.4 = [9 x i8] c"demos/%s\00"
@.str.5 = [21 x i8] c"cam script imported\0A\00"
@.str.6 = [46 x i8] c"CG_Democam_ImportCams_f: no valid file found\0A\00"
define void @CG_Democam_ImportCams_f() {
%1 = tail call i32 (...) @trap_Cmd_Argc()
%2 = icmp slt i32 %1, 2
br i1 %2, label %18, label %3
3: ; preds = %0
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i8* @trap_Cmd_Argv(i32 1)
%6 = tail call i32 @strlen(i8* %5)
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%8 = add i32 %4, 1
%9 = add i32 %8, %6
%10 = add i32 %9, %7
%11 = tail call i8* @trap_MemAlloc(i32 %10, i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.3, i64 0, i64 0), i32 1682)
%12 = tail call i8* @trap_Cmd_Argv(i32 1)
%13 = tail call i32 @Q_snprintfz(i8* %11, i32 %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%14 = tail call i32 @COM_ReplaceExtension(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%15 = tail call i64 @CG_LoadRecamScriptFile(i8* %11)
%16 = icmp eq i64 %15, 0
%17 = select i1 %16, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0)
br label %18
18: ; preds = %3, %0
%19 = phi i8* [ getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), %0 ], [ %17, %3 ]
%20 = tail call i32 @CG_Printf(i8* %19)
ret void
}