#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 */
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(int /*<<< orphan*/, void **);
int /*<<< orphan*/ Z_Free(char *);
char *Z_Malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
void Cmd_Exec_f(void) {
  char *f, *f2;
  int len;
  if (Cmd_Argc() != 2) {
    Com_Printf("exec <filename> : execute a script file\n");
    return;
  }
  len = FS_LoadFile(Cmd_Argv(1), (void **)&f);
  if (!f) {
    Com_Printf("couldn't exec %s\n", Cmd_Argv(1));
    return;
  }
  Com_Printf("execing %s\n", Cmd_Argv(1));
  f2 = Z_Malloc(len + 2);
  memcpy(f2, f, len);
  f2[len] = '\n';
  f2[len + 1] = '\0';
  Cbuf_InsertText(f2);
  Z_Free(f2);
  FS_FreeFile(f);
}


x86 assembly (clang, -O0):
<Cmd_Exec_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <Cmd_Argc@plt>
cmp    $0x2,%eax
je     11bb <Cmd_Exec_f+0x2b>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1090 <Com_Printf@plt>
jmp    126e <Cmd_Exec_f+0xde>
mov    $0x1,%edi
call   10a0 <Cmd_Argv@plt>
mov    %eax,%edi
lea    -0x8(%rbp),%rsi
call   10b0 <FS_LoadFile@plt>
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11fd <Cmd_Exec_f+0x6d>
mov    $0x1,%edi
call   10a0 <Cmd_Argv@plt>
mov    %eax,%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1090 <Com_Printf@plt>
jmp    126e <Cmd_Exec_f+0xde>
mov    $0x1,%edi
call   10a0 <Cmd_Argv@plt>
mov    %eax,%esi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1090 <Com_Printf@plt>
mov    -0x14(%rbp),%edi
add    $0x2,%edi
call   1080 <Z_Malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0xa,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1070 <Cbuf_InsertText@plt>
mov    -0x10(%rbp),%rdi
call   1030 <Z_Free@plt>
mov    -0x8(%rbp),%rdi
call   1050 <FS_FreeFile@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Cmd_Exec_f>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <Cmd_Argc@plt>
cmp    $0x2,%eax
jne    1219 <Cmd_Exec_f+0x89>
mov    $0x1,%edi
call   10a0 <Cmd_Argv@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   10b0 <FS_LoadFile@plt>
mov    %eax,%r14d
mov    (%rsp),%rbx
mov    $0x1,%edi
call   10a0 <Cmd_Argv@plt>
test   %rbx,%rbx
je     122e <Cmd_Exec_f+0x9e>
lea    0xe6a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <Com_Printf@plt>
lea    0x2(%r14),%edi
call   1080 <Z_Malloc@plt>
mov    %rax,%rbx
mov    (%rsp),%rsi
mov    %rax,%rdi
mov    %r14d,%edx
call   1060 <memcpy@plt>
movslq %r14d,%rax
movw   $0xa,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1070 <Cbuf_InsertText@plt>
mov    %rbx,%rdi
call   1030 <Z_Free@plt>
mov    (%rsp),%rdi
call   1050 <FS_FreeFile@plt>
jmp    123e <Cmd_Exec_f+0xae>
lea    0xde0(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <Com_Printf@plt>
lea    0xdf4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <Com_Printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [41 x i8] c"exec <filename> : execute a script file\0A\00"
@.str.1 = [18 x i8] c"couldn't exec %s\0A\00"
@.str.2 = [12 x i8] c"execing %s\0A\00"
define void @Cmd_Exec_f() {
%1 = alloca i8*
%2 = alloca 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 %41
8: ; preds = %0
%9 = call i32 @Cmd_Argv(i32 1)
%10 = call i32 @FS_LoadFile(i32 %9, i8** %1)
store i32 %10, i32* %3
%11 = load i8*, i8** %1
%12 = icmp ne i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = call i32 @Cmd_Argv(i32 1)
%15 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %41
16: ; preds = %8
%17 = call i32 @Cmd_Argv(i32 1)
%18 = call i32 (i8*, ...) @Com_Printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 2
%21 = call i8* @Z_Malloc(i32 %20)
store i8* %21, i8** %2
%22 = load i8*, i8** %2
%23 = load i8*, i8** %1
%24 = load i32, i32* %3
%25 = call i32 @memcpy(i8* %22, i8* %23, i32 %24)
%26 = load i8*, i8** %2
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 10, i8* %29
%30 = load i8*, i8** %2
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 0, i8* %34
%35 = load i8*, i8** %2
%36 = call i32 @Cbuf_InsertText(i8* %35)
%37 = load i8*, i8** %2
%38 = call i32 @Z_Free(i8* %37)
%39 = load i8*, i8** %1
%40 = call i32 @FS_FreeFile(i8* %39)
br label %41
41: ; preds = %16, %13, %6
ret void
}

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