#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 */
char *GetFieldValue(char *, char *, int, char *, int);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ unsetenv(char *);
void SetEnv(char *S, int Env) {
  char Field[256];
  char Value[1024];
  while (S && (S[0] != '\0')) {
    S = GetFieldValue(S, Field, 256, Value, 1024);
    if (Value[0] != '\0') {
      switch (Env) {
      case 0:
        unsetenv(Field);
        break;
      case 1:
        setenv(Field, Value, 1);
        break;
      default:
        break;
      }
    }
  }
}


x86 assembly (clang, -O0):
<SetEnv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x520,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x511(%rbp)
je     1168 <SetEnv+0x38>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x511(%rbp)
mov    -0x511(%rbp),%al
test   $0x1,%al
jne    117b <SetEnv+0x4b>
jmp    1218 <SetEnv+0xe8>
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
lea    -0x510(%rbp),%rcx
mov    $0x100,%edx
mov    $0x400,%r8d
call   1040 <GetFieldValue@plt>
mov    %rax,-0x8(%rbp)
movsbl -0x510(%rbp),%eax
cmp    $0x0,%eax
je     1213 <SetEnv+0xe3>
mov    -0xc(%rbp),%eax
mov    %eax,-0x518(%rbp)
test   %eax,%eax
je     11db <SetEnv+0xab>
jmp    11c7 <SetEnv+0x97>
mov    -0x518(%rbp),%eax
sub    $0x1,%eax
je     11ec <SetEnv+0xbc>
jmp    1209 <SetEnv+0xd9>
lea    -0x110(%rbp),%rdi
call   1050 <unsetenv@plt>
jmp    120e <SetEnv+0xde>
lea    -0x110(%rbp),%rdi
lea    -0x510(%rbp),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
jmp    120e <SetEnv+0xde>
jmp    120e <SetEnv+0xde>
jmp    1213 <SetEnv+0xe3>
jmp    1142 <SetEnv+0x12>
add    $0x520,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetEnv>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x508,%rsp
test   %rdi,%rdi
je     11b3 <SetEnv+0x83>
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rsp,%r14
lea    0x100(%rsp),%r15
jmp    1175 <SetEnv+0x45>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
test   %rbx,%rbx
je     11b3 <SetEnv+0x83>
cmpb   $0x0,(%rbx)
je     11b3 <SetEnv+0x83>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x100,%edx
mov    %r15,%rcx
mov    $0x400,%r8d
call   1040 <GetFieldValue@plt>
mov    %rax,%rbx
cmpb   $0x0,0x100(%rsp)
je     1170 <SetEnv+0x40>
cmp    $0x1,%ebp
je     1160 <SetEnv+0x30>
test   %ebp,%ebp
jne    1170 <SetEnv+0x40>
mov    %r14,%rdi
call   1050 <unsetenv@plt>
jmp    1170 <SetEnv+0x40>
add    $0x508,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @SetEnv(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca [1024 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
br label %7
7: ; preds = %38, %2
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br label %16
16: ; preds = %10, %7
%17 = phi i1 [ false, %7 ], [ %15, %10 ]
br i1 %17, label %18, label %39
18: ; preds = %16
%19 = load i8*, i8** %3
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%22 = call i8* @GetFieldValue(i8* %19, i8* %20, i32 256, i8* %21, i32 1024)
store i8* %22, i8** %3
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %18
%28 = load i32, i32* %4
switch i32 %28, label %36 [
i32 0, label %29
i32 1, label %32
]
29: ; preds = %27
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%31 = call i32 @unsetenv(i8* %30)
br label %37
32: ; preds = %27
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%35 = call i32 @setenv(i8* %33, i8* %34, i32 1)
br label %37
36: ; preds = %27
br label %37
37: ; preds = %36, %32, %29
br label %38
38: ; preds = %37, %18
br label %7
39: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @SetEnv(i8* %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp eq i8* %0, null
br i1 %7, label %23, label %8
8: ; preds = %2, %21
%9 = phi i8* [ %13, %21 ], [ %0, %2 ]
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %8
%13 = call i8* @GetFieldValue(i8* %9, i8* %5, i32 256, i8* %6, i32 1024)
%14 = load i8, i8* %6
%15 = icmp eq i8 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %12
switch i32 %1, label %21 [
i32 0, label %17
i32 1, label %19
]
17: ; preds = %16
%18 = call i32 @unsetenv(i8* %5)
br label %21
19: ; preds = %16
%20 = call i32 @setenv(i8* %5, i8* %6, i32 1)
br label %21
21: ; preds = %17, %19, %16, %12
%22 = icmp eq i8* %13, null
br i1 %22, label %23, label %8
23: ; preds = %8, %21, %2
ret void
}