#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();
char *Cmd_Argv(int);
int /*<<< orphan*/ Com_Printf(char *, char *, char *);
char *getenv(char *);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void CL_Setenv_f(void) {
  int argc = Cmd_Argc();
  if (argc > 2) {
    char buffer[1024];
    int i;
    strcpy(buffer, Cmd_Argv(1));
    strcat(buffer, "=");
    for (i = 2; i < argc; i++) {
      strcat(buffer, Cmd_Argv(i));
      strcat(buffer, " ");
    }
    putenv(buffer);
  } else if (argc == 2) {
    char *env = getenv(Cmd_Argv(1));
    if (env) {
      Com_Printf("%s=%s\n", Cmd_Argv(1), env);
    } else {
      Com_Printf("%s undefined\n", Cmd_Argv(1), env);
    }
  }
}


x86 assembly (clang, -O0):
<CL_Setenv_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    $0x0,%al
call   1050 <Cmd_Argc@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x2,-0x4(%rbp)
jle    1242 <CL_Setenv_f+0xd2>
lea    -0x410(%rbp),%rax
mov    %rax,-0x428(%rbp)
mov    $0x1,%edi
call   1080 <Cmd_Argv@plt>
mov    -0x428(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    -0x410(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1090 <strcat@plt>
movl   $0x2,-0x414(%rbp)
mov    -0x414(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1231 <CL_Setenv_f+0xc1>
lea    -0x410(%rbp),%rax
mov    %rax,-0x430(%rbp)
mov    -0x414(%rbp),%edi
call   1080 <Cmd_Argv@plt>
mov    -0x430(%rbp),%rdi
mov    %rax,%rsi
call   1090 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    11d3 <CL_Setenv_f+0x63>
lea    -0x410(%rbp),%rdi
call   1060 <putenv@plt>
jmp    12c2 <CL_Setenv_f+0x152>
cmpl   $0x2,-0x4(%rbp)
jne    12bd <CL_Setenv_f+0x14d>
mov    $0x1,%edi
call   1080 <Cmd_Argv@plt>
mov    %rax,%rdi
call   1030 <getenv@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     1298 <CL_Setenv_f+0x128>
mov    $0x1,%edi
call   1080 <Cmd_Argv@plt>
mov    %rax,%rsi
mov    -0x420(%rbp),%rdx
lea    0xd76(%rip),%rdi
call   1070 <Com_Printf@plt>
jmp    12b8 <CL_Setenv_f+0x148>
mov    $0x1,%edi
call   1080 <Cmd_Argv@plt>
mov    %rax,%rsi
mov    -0x420(%rbp),%rdx
lea    0xd58(%rip),%rdi
call   1070 <Com_Printf@plt>
jmp    12bd <CL_Setenv_f+0x14d>
jmp    12c2 <CL_Setenv_f+0x152>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CL_Setenv_f>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
xor    %eax,%eax
call   1050 <Cmd_Argc@plt>
mov    %eax,%r14d
cmp    $0x3,%eax
jl     11ef <CL_Setenv_f+0x7f>
mov    $0x1,%edi
call   1080 <Cmd_Argv@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    $0x2,%ebp
lea    0xe43(%rip),%r15
nop
mov    %ebp,%edi
call   1080 <Cmd_Argv@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    11c0 <CL_Setenv_f+0x50>
mov    %rsp,%rdi
call   1060 <putenv@plt>
jmp    1228 <CL_Setenv_f+0xb8>
cmp    $0x2,%r14d
jne    1228 <CL_Setenv_f+0xb8>
mov    $0x1,%edi
call   1080 <Cmd_Argv@plt>
mov    %rax,%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1080 <Cmd_Argv@plt>
mov    %rax,%rsi
test   %rbx,%rbx
je     1236 <CL_Setenv_f+0xc6>
lea    0xde1(%rip),%rdi
mov    %rbx,%rdx
jmp    123f <CL_Setenv_f+0xcf>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdce(%rip),%rdi
xor    %edx,%edx
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <Com_Printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"=\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [7 x i8] c"%s=%s\0A\00"
@.str.3 = [14 x i8] c"%s undefined\0A\00"
define void @CL_Setenv_f() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = alloca i8*
%5 = call i32 (...) @Cmd_Argc()
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, 2
br i1 %7, label %8, label %31
8: ; preds = %0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%10 = call i8* @Cmd_Argv(i32 1)
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%13 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %3
br label %14
14: ; preds = %25, %8
%15 = load i32, i32* %3
%16 = load i32, i32* %1
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %28
18: ; preds = %14
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%20 = load i32, i32* %3
%21 = call i8* @Cmd_Argv(i32 %20)
%22 = call i32 @strcat(i8* %19, i8* %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %18
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %14
28: ; preds = %14
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%30 = call i32 @putenv(i8* %29)
br label %49
31: ; preds = %0
%32 = load i32, i32* %1
%33 = icmp eq i32 %32, 2
br i1 %33, label %34, label %48
34: ; preds = %31
%35 = call i8* @Cmd_Argv(i32 1)
%36 = call i8* @getenv(i8* %35)
store i8* %36, i8** %4
%37 = load i8*, i8** %4
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = call i8* @Cmd_Argv(i32 1)
%41 = load i8*, i8** %4
%42 = call i32 @Com_Printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %40, i8* %41)
br label %47
43: ; preds = %34
%44 = call i8* @Cmd_Argv(i32 1)
%45 = load i8*, i8** %4
%46 = call i32 @Com_Printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %44, i8* %45)
br label %47
47: ; preds = %43, %39
br label %48
48: ; preds = %47, %31
br label %49
49: ; preds = %48, %28
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"=\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [7 x i8] c"%s=%s\0A\00"
@.str.3 = [14 x i8] c"%s undefined\0A\00"
define void @CL_Setenv_f() {
%1 = alloca [1024 x i8]
%2 = tail call i32 (...) @Cmd_Argc()
%3 = icmp sgt i32 %2, 2
br i1 %3, label %4, label %18
4: ; preds = %0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%6 = tail call i8* @Cmd_Argv(i32 1)
%7 = call i32 @strcpy(i8* %5, i8* %6)
%8 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %4, %9
%10 = phi i32 [ 2, %4 ], [ %14, %9 ]
%11 = call i8* @Cmd_Argv(i32 %10)
%12 = call i32 @strcat(i8* %5, i8* %11)
%13 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = add nuw nsw i32 %10, 1
%15 = icmp eq i32 %14, %2
br i1 %15, label %16, label %9
16: ; preds = %9
%17 = call i32 @putenv(i8* %5)
br label %29
18: ; preds = %0
%19 = icmp eq i32 %2, 2
br i1 %19, label %20, label %29
20: ; preds = %18
%21 = tail call i8* @Cmd_Argv(i32 1)
%22 = tail call i8* @getenv(i8* %21)
%23 = icmp eq i8* %22, null
%24 = tail call i8* @Cmd_Argv(i32 1)
br i1 %23, label %27, label %25
25: ; preds = %20
%26 = tail call i32 @Com_Printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8* %22)
br label %29
27: ; preds = %20
%28 = tail call i32 @Com_Printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %24, i8* null)
br label %29
29: ; preds = %25, %27, %18, %16
ret void
}