#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 Cmd_Argc();
int /*<<< orphan*/ Cmd_Argv(int);
int /*<<< orphan*/ Cmd_EndTokenizedString();
int /*<<< orphan*/ Cmd_TokenizeString(char *);
int /*<<< orphan*/ Com_PrintError(char *, char *);
char *CopyString(int /*<<< orphan*/);
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execv(char *, char **);
char *strerror(int /*<<< orphan*/);
void Sys_ReplaceProcess(char *cmdline) {
  int i;
  char *argv[256];
  Cmd_TokenizeString(cmdline);
  if (Cmd_Argc() < 256) {
    for (i = 0; i < Cmd_Argc(); i++) {
      argv[i] = CopyString(Cmd_Argv(i));
    }
    argv[i] = NULL;
    execv(argv[0], argv);
    Com_PrintError("Sys_ReplaceProcess: execv failed: %s\n", strerror(errno));
  } else {
    Com_PrintError("Sys_ReplaceProcess: Exceeded limit of 256 commandline "
                   "arguments.\nCommandline is: %s\n",
                   cmdline);
  }
  Cmd_EndTokenizedString();
  _exit(0);
}


x86 assembly (clang, -O0):
<Sys_ReplaceProcess>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <Cmd_TokenizeString@plt>
mov    $0x0,%al
call   1040 <Cmd_Argc@plt>
cmp    $0x100,%eax
jge    1252 <Sys_ReplaceProcess+0xc2>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x814(%rbp)
mov    $0x0,%al
call   1040 <Cmd_Argc@plt>
mov    %eax,%ecx
mov    -0x814(%rbp),%eax
cmp    %ecx,%eax
jge    120d <Sys_ReplaceProcess+0x7d>
mov    -0xc(%rbp),%edi
call   1080 <Cmd_Argv@plt>
mov    %eax,%edi
call   1050 <CopyString@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
mov    %rcx,-0x810(%rbp,%rax,8)
ff
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c1 <Sys_ReplaceProcess+0x31>
movslq -0xc(%rbp),%rax
movq   $0x0,-0x810(%rbp,%rax,8)
mov    -0x810(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   10b0 <execv@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xdb8(%rip),%rdi
call   1090 <Com_PrintError@plt>
jmp    1262 <Sys_ReplaceProcess+0xd2>
mov    -0x8(%rbp),%rsi
lea    0xdc9(%rip),%rdi
call   1090 <Com_PrintError@plt>
mov    $0x0,%al
call   1060 <Cmd_EndTokenizedString@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<Sys_ReplaceProcess>:
push   %rbx
sub    $0x800,%rsp
mov    %rdi,%rbx
call   1070 <Cmd_TokenizeString@plt>
xor    %eax,%eax
call   1040 <Cmd_Argc@plt>
cmp    $0xff,%eax
jg     1212 <Sys_ReplaceProcess+0x82>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <Cmd_Argc@plt>
test   %eax,%eax
jle    11e4 <Sys_ReplaceProcess+0x54>
xor    %ebx,%ebx
nopl   (%rax)
mov    %ebx,%edi
call   1080 <Cmd_Argv@plt>
mov    %eax,%edi
call   1050 <CopyString@plt>
mov    %rax,(%rsp,%rbx,8)
add    $0x1,%rbx
xor    %eax,%eax
call   1040 <Cmd_Argc@plt>
cltq
cmp    %rax,%rbx
jl     11c0 <Sys_ReplaceProcess+0x30>
movq   $0x0,(%rsp,%rbx,8)
mov    (%rsp),%rdi
mov    %rsp,%rsi
call   10b0 <execv@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdf3(%rip),%rdi
mov    %rax,%rsi
jmp    121c <Sys_ReplaceProcess+0x8c>
lea    0xe0d(%rip),%rdi
mov    %rbx,%rsi
call   1090 <Com_PrintError@plt>
xor    %eax,%eax
call   1060 <Cmd_EndTokenizedString@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"Sys_ReplaceProcess: execv failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [85 x i8] c"Sys_ReplaceProcess: Exceeded limit of 256 commandline arguments.\0ACommandline is: %s\0A\00"
define void @Sys_ReplaceProcess(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [256 x i8*]
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @Cmd_TokenizeString(i8* %5)
%7 = call i32 (...) @Cmd_Argc()
%8 = icmp slt i32 %7, 256
br i1 %8, label %9, label %35
9: ; preds = %1
store i32 0, i32* %3
br label %10
10: ; preds = %21, %9
%11 = load i32, i32* %3
%12 = call i32 (...) @Cmd_Argc()
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i32, i32* %3
%16 = call i32 @Cmd_Argv(i32 %15)
%17 = call i8* @CopyString(i32 %16)
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [256 x i8*], [256 x i8*]* %4, i64 0, i64 %19
store i8* %17, i8** %20
br label %21
21: ; preds = %14
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %10
24: ; preds = %10
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [256 x i8*], [256 x i8*]* %4, i64 0, i64 %26
store i8* null, i8** %27
%28 = getelementptr inbounds [256 x i8*], [256 x i8*]* %4, i64 0, i64 0
%29 = load i8*, i8** %28
%30 = getelementptr inbounds [256 x i8*], [256 x i8*]* %4, i64 0, i64 0
%31 = call i32 @execv(i8* %29, i8** %30)
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 @Com_PrintError(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %38
35: ; preds = %1
%36 = load i8*, i8** %2
%37 = call i32 @Com_PrintError(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.1, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %35, %24
%39 = call i32 (...) @Cmd_EndTokenizedString()
%40 = call i32 @_exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [38 x i8] c"Sys_ReplaceProcess: execv failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [85 x i8] c"Sys_ReplaceProcess: Exceeded limit of 256 commandline arguments.\0ACommandline is: %s\0A\00"
define void @Sys_ReplaceProcess(i8* %0) {
%2 = alloca [256 x i8*]
%3 = bitcast [256 x i8*]* %2 to i8*
%4 = tail call i32 @Cmd_TokenizeString(i8* %0)
%5 = tail call i32 (...) @Cmd_Argc()
%6 = icmp slt i32 %5, 256
br i1 %6, label %7, label %31
7: ; preds = %1
%8 = tail call i32 (...) @Cmd_Argc()
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %22
10: ; preds = %7, %10
%11 = phi i64 [ %16, %10 ], [ 0, %7 ]
%12 = trunc i64 %11 to i32
%13 = tail call i32 @Cmd_Argv(i32 %12)
%14 = tail call i8* @CopyString(i32 %13)
%15 = getelementptr inbounds [256 x i8*], [256 x i8*]* %2, i64 0, i64 %11
store i8* %14, i8** %15
%16 = add nuw nsw i64 %11, 1
%17 = tail call i32 (...) @Cmd_Argc()
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %10, label %20
20: ; preds = %10
%21 = and i64 %16, 4294967295
br label %22
22: ; preds = %20, %7
%23 = phi i64 [ 0, %7 ], [ %21, %20 ]
%24 = getelementptr inbounds [256 x i8*], [256 x i8*]* %2, i64 0, i64 %23
store i8* null, i8** %24
%25 = getelementptr inbounds [256 x i8*], [256 x i8*]* %2, i64 0, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @execv(i8* %26, i8** %25)
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 @Com_PrintError(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %29)
br label %33
31: ; preds = %1
%32 = tail call i32 @Com_PrintError(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %33
33: ; preds = %31, %22
%34 = call i32 (...) @Cmd_EndTokenizedString()
%35 = call i32 @_exit(i32 0)
unreachable
}