#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(void *);
int /*<<< orphan*/ FS_ReadFile(char *, void **);
int /*<<< orphan*/ Q_strncpyz(char *, int /*<<< orphan*/, int);
void Cmd_Exec_f(void) {
  union {
    char *c;
    void *v;
  } f;
  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");
  FS_ReadFile(filename, &f.v);
  if (!f.c) {
    Com_Printf("couldn't exec %s\n", Cmd_Argv(1));
    return;
  }
  Com_Printf("execing %s\n", Cmd_Argv(1));
  Cbuf_InsertText(f.c);
  FS_FreeFile(f.v);
}


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    1245 <Cmd_Exec_f+0xc5>
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>
cmpq   $0x0,-0x8(%rbp)
jne    1219 <Cmd_Exec_f+0x99>
mov    $0x1,%edi
call   1090 <Cmd_Argv@plt>
mov    %eax,%esi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1080 <Com_Printf@plt>
jmp    1245 <Cmd_Exec_f+0xc5>
mov    $0x1,%edi
call   1090 <Cmd_Argv@plt>
mov    %eax,%esi
lea    0xe14(%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):
%union.anon = type { i8* }
@.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 %union.anon
%2 = alloca [64 x i8]
%3 = call i32 (...) @Cmd_Argc()
%4 = icmp ne i32 %3, 2
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %31
7: ; preds = %0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%9 = call i32 @Cmd_Argv(i32 1)
%10 = call i32 @Q_strncpyz(i8* %8, i32 %9, i32 64)
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%12 = call i32 @COM_DefaultExtension(i8* %11, i32 64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%14 = bitcast %union.anon* %1 to i8**
%15 = call i32 @FS_ReadFile(i8* %13, i8** %14)
%16 = bitcast %union.anon* %1 to i8**
%17 = load i8*, i8** %16
%18 = icmp ne i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %7
%20 = call i32 @Cmd_Argv(i32 1)
%21 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %31
22: ; preds = %7
%23 = call i32 @Cmd_Argv(i32 1)
%24 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = bitcast %union.anon* %1 to i8**
%26 = load i8*, i8** %25
%27 = call i32 @Cbuf_InsertText(i8* %26)
%28 = bitcast %union.anon* %1 to i8**
%29 = load i8*, i8** %28
%30 = call i32 @FS_FreeFile(i8* %29)
br label %31
31: ; preds = %22, %19, %5
ret void
}

LLVM IR (-O2):
%union.anon = type { i8* }
@.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 %union.anon
%2 = alloca [64 x i8]
%3 = bitcast %union.anon* %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 %26
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 = getelementptr inbounds %union.anon, %union.anon* %1, i64 0, i32 0
%14 = call i32 @FS_ReadFile(i8* %4, i8** %13)
%15 = load i8*, i8** %13
%16 = icmp eq i8* %15, null
%17 = call i32 @Cmd_Argv(i32 1)
br i1 %16, label %18, label %20
18: ; preds = %9
%19 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %26
20: ; preds = %9
%21 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%22 = load i8*, i8** %13
%23 = call i32 @Cbuf_InsertText(i8* %22)
%24 = load i8*, i8** %13
%25 = call i32 @FS_FreeFile(i8* %24)
br label %26
26: ; preds = %20, %18, %7
ret void
}