#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_ArgsFrom(int);
char *Cmd_Argv(int);
int /*<<< orphan*/ Com_Printf(char *, char *, ...);
int /*<<< orphan*/ Sys_SetEnv(char *, char *);
char *getenv(char *);
void Com_Setenv_f(void) {
  int argc = Cmd_Argc();
  char *arg1 = Cmd_Argv(1);
  if (argc > 2) {
    char *arg2 = Cmd_ArgsFrom(2);
    Sys_SetEnv(arg1, arg2);
  } else if (argc == 2) {
    char *env = getenv(arg1);
    if (env)
      Com_Printf("%s=%s\n", arg1, env);
    else
      Com_Printf("%s undefined\n", arg1);
  }
}


x86 assembly (clang, -O0):
<Com_Setenv_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <Cmd_Argc@plt>
mov    %eax,-0x4(%rbp)
mov    $0x1,%edi
call   1080 <Cmd_Argv@plt>
mov    %rax,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
jle    11aa <Com_Setenv_f+0x4a>
mov    $0x2,%edi
call   1050 <Cmd_ArgsFrom@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <Sys_SetEnv@plt>
jmp    1203 <Com_Setenv_f+0xa3>
cmpl   $0x2,-0x4(%rbp)
jne    11fe <Com_Setenv_f+0x9e>
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e7 <Com_Setenv_f+0x87>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1070 <Com_Printf@plt>
jmp    11f9 <Com_Setenv_f+0x99>
mov    -0x10(%rbp),%rsi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1070 <Com_Printf@plt>
jmp    11fe <Com_Setenv_f+0x9e>
jmp    1203 <Com_Setenv_f+0xa3>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Com_Setenv_f>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <Cmd_Argc@plt>
mov    %eax,%ebp
mov    $0x1,%edi
call   1080 <Cmd_Argv@plt>
mov    %rax,%rbx
cmp    $0x3,%ebp
jl     1199 <Com_Setenv_f+0x39>
mov    $0x2,%edi
call   1050 <Cmd_ArgsFrom@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <Sys_SetEnv@plt>
cmp    $0x2,%ebp
jne    11c5 <Com_Setenv_f+0x65>
mov    %rbx,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11cc <Com_Setenv_f+0x6c>
lea    0xe4e(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1070 <Com_Printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe34(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1070 <Com_Printf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%s=%s\0A\00"
@.str.1 = [14 x i8] c"%s undefined\0A\00"
define void @Com_Setenv_f() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i32 (...) @Cmd_Argc()
store i32 %5, i32* %1
%6 = call i8* @Cmd_Argv(i32 1)
store i8* %6, i8** %2
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 2
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = call i8* @Cmd_ArgsFrom(i32 2)
store i8* %10, i8** %3
%11 = load i8*, i8** %2
%12 = load i8*, i8** %3
%13 = call i32 @Sys_SetEnv(i8* %11, i8* %12)
br label %31
14: ; preds = %0
%15 = load i32, i32* %1
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %30
17: ; preds = %14
%18 = load i8*, i8** %2
%19 = call i8* @getenv(i8* %18)
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i8*, i8** %2
%24 = load i8*, i8** %4
%25 = call i32 (i8*, i8*, ...) @Com_Printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %24)
br label %29
26: ; preds = %17
%27 = load i8*, i8** %2
%28 = call i32 (i8*, i8*, ...) @Com_Printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %26, %22
br label %30
30: ; preds = %29, %14
br label %31
31: ; preds = %30, %9
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s=%s\0A\00"
@.str.1 = [14 x i8] c"%s undefined\0A\00"
define void @Com_Setenv_f() {
%1 = tail call i32 (...) @Cmd_Argc()
%2 = tail call i8* @Cmd_Argv(i32 1)
%3 = icmp sgt i32 %1, 2
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i8* @Cmd_ArgsFrom(i32 2)
%6 = tail call i32 @Sys_SetEnv(i8* %2, i8* %5)
br label %16
7: ; preds = %0
%8 = icmp eq i32 %1, 2
br i1 %8, label %9, label %16
9: ; preds = %7
%10 = tail call i8* @getenv(i8* %2)
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 (i8*, i8*, ...) @Com_Printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %10)
br label %16
14: ; preds = %9
%15 = tail call i32 (i8*, i8*, ...) @Com_Printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %16
16: ; preds = %12, %14, %7, %4
ret void
}