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

/* Variables and functions */
int /*<<< orphan*/ COM_DefaultExtension(char *, int, char *);
int /*<<< orphan*/ Cbuf_InsertText(char *);
int Cmd_Argc();
int /*<<< orphan*/ Cmd_Argv(int);
int /*<<< orphan*/ Com_Printf(char *, ...);
int /*<<< orphan*/ FS_FreeFile(char *);
int FS_ReadFile(char *, void **);
int /*<<< orphan*/ Q_strncpyz(char *, int /*<<< orphan*/, int);
void Cmd_Exec_f(void) {
  char *f;
  int len;
  char filename[64];
  if (Cmd_Argc() != 2) {
    Com_Printf("exec <filename> : execute a script file\n");
    return;
  }
  Q_strncpyz(filename, Cmd_Argv(1), sizeof(filename));
  COM_DefaultExtension(filename, sizeof(filename), ".cfg");
  len = FS_ReadFile(filename, (void **)&f);
  if (!f) {
    Com_Printf("couldn't exec %s\n", Cmd_Argv(1));
    return;
  }
  Com_Printf("execing %s\n", Cmd_Argv(1));
  Cbuf_InsertText(f);
  FS_FreeFile(f);
}


x86 assembly (clang, -O0):
<Cmd_Exec_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    $0x0,%al
call   1030 <Cmd_Argc@plt>
cmp    $0x2,%eax
je     11ab <Cmd_Exec_f+0x2b>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1080 <Com_Printf@plt>
jmp    1248 <Cmd_Exec_f+0xc8>
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    $0x1,%edi
call   1090 <Cmd_Argv@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%esi
mov    $0x40,%edx
call   10a0 <Q_strncpyz@plt>
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
lea    0xe4c(%rip),%rdx
call   1070 <COM_DefaultExtension@plt>
lea    -0x50(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <FS_ReadFile@plt>
mov    %eax,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    121c <Cmd_Exec_f+0x9c>
mov    $0x1,%edi
call   1090 <Cmd_Argv@plt>
mov    %eax,%esi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1080 <Com_Printf@plt>
jmp    1248 <Cmd_Exec_f+0xc8>
mov    $0x1,%edi
call   1090 <Cmd_Argv@plt>
mov    %eax,%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1080 <Com_Printf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <Cbuf_InsertText@plt>
mov    -0x8(%rbp),%rdi
call   1040 <FS_FreeFile@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Cmd_Exec_f>:
push   %rbx
sub    $0x50,%rsp
xor    %eax,%eax
call   1030 <Cmd_Argc@plt>
cmp    $0x2,%eax
jne    120a <Cmd_Exec_f+0x8a>
mov    $0x1,%edi
call   1090 <Cmd_Argv@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x40,%edx
call   10a0 <Q_strncpyz@plt>
lea    0xe73(%rip),%rdx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1070 <COM_DefaultExtension@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <FS_ReadFile@plt>
mov    0x8(%rsp),%rbx
mov    $0x1,%edi
call   1090 <Cmd_Argv@plt>
test   %rbx,%rbx
je     121d <Cmd_Exec_f+0x9d>
lea    0xe55(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <Com_Printf@plt>
mov    0x8(%rsp),%rdi
call   1060 <Cbuf_InsertText@plt>
mov    0x8(%rsp),%rdi
call   1040 <FS_FreeFile@plt>
jmp    122d <Cmd_Exec_f+0xad>
lea    0xdef(%rip),%rdi
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
jmp    1080 <Com_Printf@plt>
lea    0xe0a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <Com_Printf@plt>
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [41 x i8] c"exec <filename> : execute a script file\0A\00"
@.str.1 = [5 x i8] c".cfg\00"
@.str.2 = [18 x i8] c"couldn't exec %s\0A\00"
@.str.3 = [12 x i8] c"execing %s\0A\00"
define void @Cmd_Exec_f() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca [64 x i8]
%4 = call i32 (...) @Cmd_Argc()
%5 = icmp ne i32 %4, 2
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %28
8: ; preds = %0
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%10 = call i32 @Cmd_Argv(i32 1)
%11 = call i32 @Q_strncpyz(i8* %9, i32 %10, i32 64)
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%13 = call i32 @COM_DefaultExtension(i8* %12, i32 64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%15 = call i32 @FS_ReadFile(i8* %14, i8** %1)
store i32 %15, i32* %2
%16 = load i8*, i8** %1
%17 = icmp ne i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %8
%19 = call i32 @Cmd_Argv(i32 1)
%20 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %28
21: ; preds = %8
%22 = call i32 @Cmd_Argv(i32 1)
%23 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i8*, i8** %1
%25 = call i32 @Cbuf_InsertText(i8* %24)
%26 = load i8*, i8** %1
%27 = call i32 @FS_FreeFile(i8* %26)
br label %28
28: ; preds = %21, %18, %6
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"exec <filename> : execute a script file\0A\00"
@.str.1 = [5 x i8] c".cfg\00"
@.str.2 = [18 x i8] c"couldn't exec %s\0A\00"
@.str.3 = [12 x i8] c"execing %s\0A\00"
define void @Cmd_Exec_f() {
%1 = alloca i8*
%2 = alloca [64 x i8]
%3 = bitcast i8** %1 to i8*
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (...) @Cmd_Argc()
%6 = icmp eq i32 %5, 2
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %25
9: ; preds = %0
%10 = tail call i32 @Cmd_Argv(i32 1)
%11 = call i32 @Q_strncpyz(i8* %4, i32 %10, i32 64)
%12 = call i32 @COM_DefaultExtension(i8* %4, i32 64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @FS_ReadFile(i8* %4, i8** %1)
%14 = load i8*, i8** %1
%15 = icmp eq i8* %14, null
%16 = call i32 @Cmd_Argv(i32 1)
br i1 %15, label %17, label %19
17: ; preds = %9
%18 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %25
19: ; preds = %9
%20 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%21 = load i8*, i8** %1
%22 = call i32 @Cbuf_InsertText(i8* %21)
%23 = load i8*, i8** %1
%24 = call i32 @FS_FreeFile(i8* %23)
br label %25
25: ; preds = %19, %17, %7
ret void
}