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

/* 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_LoadFile(char *, void **);
int /*<<< orphan*/ Q_strncpyz(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strchr(char *, char);
void Cmd_Exec_f(void) {
  char *f, config[64];
  int len;
  if (Cmd_Argc() != 2) {
    Com_Printf("exec <filename> : execute a script file\n");
    return;
  }
  Q_strncpyz(config, Cmd_Argv(1), sizeof(config));
  len = FS_LoadFile(config, (void **)&f);
  if (!f || !len) {
    if (!strchr(config, '.')) {
      COM_DefaultExtension(config, sizeof(config), ".cfg");
      len = FS_LoadFile(config, (void **)&f);
    }
    if (!f || !len) {
      Com_Printf("couldn't exec %s\n", config);
      return;
    }
  }
  Com_Printf("execing %s\n", config);
  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     11bb <Cmd_Exec_f+0x2b>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1080 <Com_Printf@plt>
jmp    1293 <Cmd_Exec_f+0x103>
lea    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    $0x1,%edi
call   1090 <Cmd_Argv@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%esi
mov    $0x40,%edx
call   10b0 <Q_strncpyz@plt>
lea    -0x50(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   10a0 <FS_LoadFile@plt>
mov    %eax,-0x54(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1202 <Cmd_Exec_f+0x72>
cmpl   $0x0,-0x54(%rbp)
jne    126f <Cmd_Exec_f+0xdf>
lea    -0x50(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
cmp    $0x0,%eax
jne    123e <Cmd_Exec_f+0xae>
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
lea    0xe00(%rip),%rdx
call   1070 <COM_DefaultExtension@plt>
lea    -0x50(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   10a0 <FS_LoadFile@plt>
mov    %eax,-0x54(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1253 <Cmd_Exec_f+0xc3>
cmpl   $0x0,-0x54(%rbp)
jne    126a <Cmd_Exec_f+0xda>
lea    -0x50(%rbp),%rsi
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1080 <Com_Printf@plt>
jmp    1293 <Cmd_Exec_f+0x103>
jmp    126f <Cmd_Exec_f+0xdf>
lea    -0x50(%rbp),%rsi
lea    0xdc6(%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    11f7 <Cmd_Exec_f+0x67>
mov    $0x1,%edi
call   1090 <Cmd_Argv@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x40,%edx
call   10b0 <Q_strncpyz@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   10a0 <FS_LoadFile@plt>
mov    %eax,%ebx
cmpq   $0x0,0x8(%rsp)
je     11da <Cmd_Exec_f+0x4a>
test   %ebx,%ebx
jne    123e <Cmd_Exec_f+0xae>
lea    0x10(%rsp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %eax,%eax
je     120a <Cmd_Exec_f+0x7a>
cmpq   $0x0,0x8(%rsp)
jne    123a <Cmd_Exec_f+0xaa>
jmp    1267 <Cmd_Exec_f+0xd7>
lea    0xe02(%rip),%rdi
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
jmp    1080 <Com_Printf@plt>
lea    0xe18(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1070 <COM_DefaultExtension@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   10a0 <FS_LoadFile@plt>
mov    %eax,%ebx
cmpq   $0x0,0x8(%rsp)
je     1267 <Cmd_Exec_f+0xd7>
test   %ebx,%ebx
je     1267 <Cmd_Exec_f+0xd7>
lea    0xdfb(%rip),%rdi
lea    0x10(%rsp),%rsi
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    127a <Cmd_Exec_f+0xea>
lea    0xdc0(%rip),%rdi
lea    0x10(%rsp),%rsi
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 [64 x i8]
%3 = alloca i32
%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 %45
8: ; preds = %0
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %2, 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]* %2, i64 0, i64 0
%13 = call i32 @FS_LoadFile(i8* %12, i8** %1)
store i32 %13, i32* %3
%14 = load i8*, i8** %1
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = load i32, i32* %3
%18 = icmp ne i32 %17, 0
br i1 %18, label %38, label %19
19: ; preds = %16, %8
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%21 = call i32 @strchr(i8* %20, i8 signext 46)
%22 = icmp ne i32 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %19
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%25 = call i32 @COM_DefaultExtension(i8* %24, i32 64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%27 = call i32 @FS_LoadFile(i8* %26, i8** %1)
store i32 %27, i32* %3
br label %28
28: ; preds = %23, %19
%29 = load i8*, i8** %1
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %3
%33 = icmp ne i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %31, %28
%35 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%36 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %35)
br label %45
37: ; preds = %31
br label %38
38: ; preds = %37, %16
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%40 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = load i8*, i8** %1
%42 = call i32 @Cbuf_InsertText(i8* %41)
%43 = load i8*, i8** %1
%44 = call i32 @FS_FreeFile(i8* %43)
br label %45
45: ; preds = %38, %34, %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 %37
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 @FS_LoadFile(i8* %4, i8** %1)
%13 = load i8*, i8** %1
%14 = icmp ne i8* %13, null
%15 = icmp ne i32 %12, 0
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %31, label %17
17: ; preds = %9
%18 = call i32 @strchr(i8* %4, i8 signext 46)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i32 @COM_DefaultExtension(i8* %4, i32 64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @FS_LoadFile(i8* %4, i8** %1)
br label %23
23: ; preds = %20, %17
%24 = phi i32 [ %12, %17 ], [ %22, %20 ]
%25 = load i8*, i8** %1
%26 = icmp ne i8* %25, null
%27 = icmp ne i32 %24, 0
%28 = select i1 %26, i1 %27, i1 false
br i1 %28, label %31, label %29
29: ; preds = %23
%30 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %37
31: ; preds = %23, %9
%32 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%33 = load i8*, i8** %1
%34 = call i32 @Cbuf_InsertText(i8* %33)
%35 = load i8*, i8** %1
%36 = call i32 @FS_FreeFile(i8* %35)
br label %37
37: ; preds = %31, %29, %7
ret void
}