#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*/ EXIT_SUCCESS;
scalar_t__ _setenv(char *, char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ exitErr(char *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int overwrite = 0;
  if (argc < 3)
    usage(argv[0]);
  if (argc == 4)
    overwrite = 1;
  if (_setenv(argv[1], argv[2], overwrite) < 0)
    exitErr("setenv");
  printf("%s=%s\n", argv[1], getenv(argv[1]));
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1193 <main+0x33>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
cmpl   $0x4,-0x8(%rbp)
jne    11a4 <main+0x44>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x14(%rbp),%edx
call   1060 <_setenv@plt>
cmp    $0x0,%rax
jge    11d2 <main+0x72>
lea    0xe33(%rip),%rdi
call   1040 <exitErr@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <getenv@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
lea    0xe0e(%rip),%rdi
call   1050 <printf@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x2,%edi
jg     1175 <main+0x15>
mov    (%rbx),%rdi
call   1070 <usage@plt>
xor    %edx,%edx
cmp    $0x4,%ebp
sete   %dl
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
call   1060 <_setenv@plt>
test   %rax,%rax
jns    119b <main+0x3b>
lea    0xe6a(%rip),%rdi
call   1040 <exitErr@plt>
mov    0x8(%rbx),%rbx
mov    %rbx,%rdi
call   1030 <getenv@plt>
lea    0xe59(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1050 <printf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"setenv\00"
@.str.1 = [7 x i8] c"%s=%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @usage(i8* %12)
br label %14
14: ; preds = %9, %2
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 4
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 1, i32* %6
br label %18
18: ; preds = %17, %14
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = load i32, i32* %6
%26 = call i64 @_setenv(i8* %21, i8* %24, i32 %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %18
%29 = call i32 @exitErr(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %18
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i8* @getenv(i8* %36)
%38 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* %37)
%39 = load i32, i32* @EXIT_SUCCESS
%40 = call i32 @exit(i32 %39)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"setenv\00"
@.str.1 = [7 x i8] c"%s=%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5)
br label %7
7: ; preds = %4, %2
%8 = icmp eq i32 %0, 4
%9 = zext i1 %8 to i32
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i64 @_setenv(i8* %11, i8* %13, i32 %9)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %7
%17 = tail call i32 @exitErr(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %7
%19 = load i8*, i8** %10
%20 = tail call i8* @getenv(i8* %19)
%21 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20)
%22 = load i32, i32* @EXIT_SUCCESS
%23 = tail call i32 @exit(i32 %22)
unreachable
}