#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 FS_ReadFile(char *, void **);
int /*<<< orphan*/ Q_strncpyz(char *, int /*<<< orphan*/, int);
void Cmd_Exec_f(void) {
  union {
    char *c;
    void *v;
  } 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, &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    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):
%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 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 %32
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 = bitcast %union.anon* %1 to i8**
%16 = call i32 @FS_ReadFile(i8* %14, i8** %15)
store i32 %16, i32* %2
%17 = bitcast %union.anon* %1 to i8**
%18 = load i8*, i8** %17
%19 = icmp ne i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %8
%21 = call i32 @Cmd_Argv(i32 1)
%22 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %32
23: ; preds = %8
%24 = call i32 @Cmd_Argv(i32 1)
%25 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = bitcast %union.anon* %1 to i8**
%27 = load i8*, i8** %26
%28 = call i32 @Cbuf_InsertText(i8* %27)
%29 = bitcast %union.anon* %1 to i8**
%30 = load i8*, i8** %29
%31 = call i32 @FS_FreeFile(i8* %30)
br label %32
32: ; preds = %23, %20, %6
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
}