#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ setenv(char *, char *, int);
int /*<<< orphan*/ stderr;
int psh_export(char **args) {
  int i;
  if (!args[1]) {
    fprintf(stderr, "Must supply a variable to export\n");
    return 1;
  } else if (!args[2]) {
    i = 0;
    while (args[1][i] != '=')
      i++;
    args[1][i] = '\0';
    if (setenv(args[1], args[1] + i + 1, 1)) {
      perror("export");
    }
  } else if (setenv(args[1], args[2], 1)) {
    perror("export");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<psh_export>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    116c <psh_export+0x3c>
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1246 <psh_export+0x116>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
jne    11f9 <psh_export+0xc9>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
je     11a9 <psh_export+0x79>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1182 <psh_export+0x52>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
cmp    $0x0,%rax
je     11f4 <psh_export+0xc4>
lea    0xe33(%rip),%rdi
call   1050 <perror@plt>
jmp    123a <psh_export+0x10a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
cmp    $0x0,%rax
je     1235 <psh_export+0x105>
lea    0xdfe(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1246 <psh_export+0x116>
jmp    123a <psh_export+0x10a>
jmp    123f <psh_export+0x10f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psh_export>:
push   %rbx
mov    %rdi,%rax
mov    0x8(%rdi),%rdi
test   %rdi,%rdi
je     1165 <psh_export+0x35>
mov    0x10(%rax),%rsi
test   %rsi,%rsi
je     1181 <psh_export+0x51>
mov    $0x1,%edx
call   1030 <setenv@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11be <psh_export+0x8e>
lea    0xec4(%rip),%rdi
call   1050 <perror@plt>
jmp    117a <psh_export+0x4a>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%ebx
jmp    11be <psh_export+0x8e>
mov    $0xffffffffffffffff,%rcx
nopl   0x0(%rax,%rax,1)
cmpb   $0x3d,0x1(%rdi,%rcx,1)
lea    0x1(%rcx),%rcx
jne    1190 <psh_export+0x60>
mov    %ecx,%ecx
movb   $0x0,(%rdi,%rcx,1)
mov    0x8(%rax),%rdi
lea    (%rdi,%rcx,1),%rsi
add    $0x1,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    11c2 <psh_export+0x92>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe59(%rip),%rdi
call   1050 <perror@plt>
jmp    11be <psh_export+0x8e>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Must supply a variable to export\0A\00"
@.str.1 = [7 x i8] c"export\00"
define i32 @psh_export(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
store i8** %0, i8*** %3
%5 = load i8**, i8*** %3
%6 = getelementptr inbounds i8*, i8** %5, i64 1
%7 = load i8*, i8** %6
%8 = icmp ne i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %67
12: ; preds = %1
%13 = load i8**, i8*** %3
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %53, label %17
17: ; preds = %12
store i32 0, i32* %4
br label %18
18: ; preds = %28, %17
%19 = load i8**, i8*** %3
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 61
br i1 %27, label %28, label %31
28: ; preds = %18
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %18
31: ; preds = %18
%32 = load i8**, i8*** %3
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
%38 = load i8**, i8*** %3
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = load i8**, i8*** %3
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = call i64 @setenv(i8* %40, i8* %47, i32 1)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %31
%51 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %52
52: ; preds = %50, %31
br label %65
53: ; preds = %12
%54 = load i8**, i8*** %3
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = load i8**, i8*** %3
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load i8*, i8** %58
%60 = call i64 @setenv(i8* %56, i8* %59, i32 1)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %53
%63 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %67
64: ; preds = %53
br label %65
65: ; preds = %64, %52
br label %66
66: ; preds = %65
store i32 0, i32* %2
br label %67
67: ; preds = %66, %62, %9
%68 = load i32, i32* %2
ret i32 %68
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Must supply a variable to export\0A\00"
@.str.1 = [7 x i8] c"export\00"
define i32 @psh_export(i8** nocapture %0) {
%2 = getelementptr inbounds i8*, i8** %0, i64 1
%3 = load i8*, i8** %2
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %33
8: ; preds = %1
%9 = getelementptr inbounds i8*, i8** %0, i64 2
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %28
12: ; preds = %8, %12
%13 = phi i64 [ %17, %12 ], [ 0, %8 ]
%14 = getelementptr inbounds i8, i8* %3, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 61
%17 = add nuw i64 %13, 1
br i1 %16, label %18, label %12
18: ; preds = %12
%19 = and i64 %13, 4294967295
%20 = getelementptr inbounds i8, i8* %3, i64 %19
store i8 0, i8* %20
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i64 %19
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = tail call i64 @setenv(i8* %21, i8* %23, i32 1)
%25 = icmp eq i64 %24, 0
br i1 %25, label %33, label %26
26: ; preds = %18
%27 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %33
28: ; preds = %8
%29 = tail call i64 @setenv(i8* %3, i8* %10, i32 1)
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %28, %18, %26, %31, %5
%34 = phi i32 [ 1, %31 ], [ 1, %5 ], [ 0, %26 ], [ 0, %18 ], [ 0, %28 ]
ret i32 %34
}