#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 errno;
int /*<<< orphan*/ perror(char *);
int setenv(char *, char *, int);
char *strtok(char *, char *);
int builtin_export(size_t argc, char **argv) {
  char *name;
  char *value;
  if (argc == 1) {
    return 1;
  }
  name = strtok(argv[1], "=");
  if (name == NULL) {
    return 1;
  }
  value = strtok(NULL, "=");
  if (value == NULL) {
    value = argv[2];
    if (value == NULL) {
      return 1;
    }
  }
  if (setenv(name, value, 1) == -1) {
    perror("setenv");
    return errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<builtin_export>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x1,-0x10(%rbp)
jne    1157 <builtin_export+0x27>
movl   $0x1,-0x4(%rbp)
jmp    120c <builtin_export+0xdc>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe9a(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1186 <builtin_export+0x56>
movl   $0x1,-0x4(%rbp)
jmp    120c <builtin_export+0xdc>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe6f(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11cd <builtin_export+0x9d>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c8 <builtin_export+0x98>
movl   $0x1,-0x4(%rbp)
jmp    120c <builtin_export+0xdc>
jmp    11cd <builtin_export+0x9d>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
cmp    $0xffffffff,%eax
jne    1205 <builtin_export+0xd5>
lea    0xe13(%rip),%rdi
call   1040 <perror@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    120c <builtin_export+0xdc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<builtin_export>:
push   %r15
push   %r14
push   %rbx
mov    $0x1,%ebx
cmp    $0x1,%rdi
je     1191 <builtin_export+0x61>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     1191 <builtin_export+0x61>
mov    %rax,%r15
lea    0xe9e(%rip),%rsi
xor    %edi,%edi
call   1050 <strtok@plt>
test   %rax,%rax
jne    1177 <builtin_export+0x47>
mov    0x10(%r14),%rax
test   %rax,%rax
je     1191 <builtin_export+0x61>
mov    %r15,%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    $0x0,%ebx
cmp    $0xffffffff,%eax
je     1199 <builtin_export+0x69>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe62(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%ebx
jmp    1191 <builtin_export+0x61>

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

LLVM IR (-O2):
@.str = [2 x i8] c"=\00"
@.str.1 = [7 x i8] c"setenv\00"
@errno = global i32 0
define i32 @builtin_export(i64 %0, i8** nocapture %1) {
%3 = icmp eq i64 %0, 1
br i1 %3, label %23, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %23, label %9
9: ; preds = %4
%10 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = icmp eq i8* %14, null
br i1 %15, label %23, label %16
16: ; preds = %12, %9
%17 = phi i8* [ %14, %12 ], [ %10, %9 ]
%18 = tail call i32 @setenv(i8* %7, i8* %17, i32 1)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @errno
br label %23
23: ; preds = %16, %12, %4, %2, %20
%24 = phi i32 [ %22, %20 ], [ 1, %2 ], [ 1, %4 ], [ 1, %12 ], [ 0, %16 ]
ret i32 %24
}