#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 */
typedef int /*<<< orphan*/ time_t;

/* Variables and functions */
char *buffer_load(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ ftsh_error(int, int, char *, ...);
char *malloc(scalar_t__);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ strlen(char *);
char *xxstrdup(char *);
int builtin_export(int line, int argc, char **argv, time_t stoptime) {
  char *expr;
  char *name;
  char *value;
  if (argc < 2) {
    ftsh_error(0, line, "export: exactly one argument needed");
    return 0;
  } else if (argc > 2) {
    ftsh_error(0, line, "export: too many arguments");
    return 0;
  }
  name = argv[1];
  value = buffer_load(name);
  if (!value)
    value = xxstrdup("");
  expr = malloc(strlen(name) + strlen(value) + 3);
  if (!expr) {
    free(name);
    free(value);
    return 0;
  }
  ftsh_error(20, line, "EXPORT %s (%s)", name, value);
  sprintf(expr, "%s=%s", name, value);
  putenv(expr);
  free(name);
  free(value);
  return 1;
}


x86 assembly (clang, -O0):
<builtin_export>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    11be <builtin_export+0x3e>
mov    -0x8(%rbp),%esi
xor    %edi,%edi
lea    0xe55(%rip),%rdx
mov    $0x0,%al
call   1080 <ftsh_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cb <builtin_export+0x14b>
cmpl   $0x2,-0xc(%rbp)
jle    11e7 <builtin_export+0x67>
mov    -0x8(%rbp),%esi
xor    %edi,%edi
lea    0xe50(%rip),%rdx
mov    $0x0,%al
call   1080 <ftsh_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cb <builtin_export+0x14b>
jmp    11ec <builtin_export+0x6c>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <buffer_load@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1220 <builtin_export+0xa0>
lea    0xe36(%rip),%rdi
call   1090 <xxstrdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
add    %rax,%rdi
add    $0x3,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1273 <builtin_export+0xf3>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cb <builtin_export+0x14b>
mov    -0x8(%rbp),%esi
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    $0x14,%edi
lea    0xdb5(%rip),%rdx
mov    $0x0,%al
call   1080 <ftsh_error@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xdaa(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1060 <putenv@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<builtin_export>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
cmp    $0x1,%esi
jg     119a <builtin_export+0x1a>
lea    0xe6b(%rip),%rdx
jmp    1244 <builtin_export+0xc4>
cmp    $0x2,%esi
jne    123d <builtin_export+0xbd>
mov    0x8(%rdx),%r14
mov    %r14,%rdi
call   1040 <buffer_load@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11c6 <builtin_export+0x46>
lea    0xe8f(%rip),%rdi
call   1090 <xxstrdup@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x3,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     125e <builtin_export+0xde>
mov    %rax,%rbx
lea    0xe4a(%rip),%rdx
mov    $0x14,%edi
mov    %ebp,%esi
mov    %r14,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1080 <ftsh_error@plt>
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <putenv@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0x1,%ebx
jmp    1251 <builtin_export+0xd1>
lea    0xde0(%rip),%rdx
xor    %ebx,%ebx
xor    %edi,%edi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <ftsh_error@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
jmp    1251 <builtin_export+0xd1>

LLVM IR (-O0):
@.str = [36 x i8] c"export: exactly one argument needed\00"
@.str.1 = [27 x i8] c"export: too many arguments\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [15 x i8] c"EXPORT %s (%s)\00"
@.str.4 = [6 x i8] c"%s=%s\00"
define i32 @builtin_export(i32 %0, i32 %1, i8** %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8** %2, i8*** %8
store i32 %3, i32* %9
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i32, i32* %6
%17 = call i32 (i32, i32, i8*, ...) @ftsh_error(i32 0, i32 %16, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %65
18: ; preds = %4
%19 = load i32, i32* %7
%20 = icmp sgt i32 %19, 2
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* %6
%23 = call i32 (i32, i32, i8*, ...) @ftsh_error(i32 0, i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %65
24: ; preds = %18
br label %25
25: ; preds = %24
%26 = load i8**, i8*** %8
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %11
%29 = load i8*, i8** %11
%30 = call i8* @buffer_load(i8* %29)
store i8* %30, i8** %12
%31 = load i8*, i8** %12
%32 = icmp ne i8* %31, null
br i1 %32, label %35, label %33
33: ; preds = %25
%34 = call i8* @xxstrdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
store i8* %34, i8** %12
br label %35
35: ; preds = %33, %25
%36 = load i8*, i8** %11
%37 = call i64 @strlen(i8* %36)
%38 = load i8*, i8** %12
%39 = call i64 @strlen(i8* %38)
%40 = add nsw i64 %37, %39
%41 = add nsw i64 %40, 3
%42 = call i8* @malloc(i64 %41)
store i8* %42, i8** %10
%43 = load i8*, i8** %10
%44 = icmp ne i8* %43, null
br i1 %44, label %50, label %45
45: ; preds = %35
%46 = load i8*, i8** %11
%47 = call i32 @free(i8* %46)
%48 = load i8*, i8** %12
%49 = call i32 @free(i8* %48)
store i32 0, i32* %5
br label %65
50: ; preds = %35
%51 = load i32, i32* %6
%52 = load i8*, i8** %11
%53 = load i8*, i8** %12
%54 = call i32 (i32, i32, i8*, ...) @ftsh_error(i32 20, i32 %51, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %52, i8* %53)
%55 = load i8*, i8** %10
%56 = load i8*, i8** %11
%57 = load i8*, i8** %12
%58 = call i32 @sprintf(i8* %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %56, i8* %57)
%59 = load i8*, i8** %10
%60 = call i32 @putenv(i8* %59)
%61 = load i8*, i8** %11
%62 = call i32 @free(i8* %61)
%63 = load i8*, i8** %12
%64 = call i32 @free(i8* %63)
store i32 1, i32* %5
br label %65
65: ; preds = %50, %45, %21, %15
%66 = load i32, i32* %5
ret i32 %66
}

LLVM IR (-O2):
@.str = [36 x i8] c"export: exactly one argument needed\00"
@.str.1 = [27 x i8] c"export: too many arguments\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [15 x i8] c"EXPORT %s (%s)\00"
@.str.4 = [6 x i8] c"%s=%s\00"
define i32 @builtin_export(i32 %0, i32 %1, i8** nocapture %2, i32 %3) {
%5 = icmp slt i32 %1, 2
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 (i32, i32, i8*, ...) @ftsh_error(i32 0, i32 %0, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %36
8: ; preds = %4
%9 = icmp eq i32 %1, 2
br i1 %9, label %12, label %10
10: ; preds = %8
%11 = tail call i32 (i32, i32, i8*, ...) @ftsh_error(i32 0, i32 %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %36
12: ; preds = %8
%13 = getelementptr inbounds i8*, i8** %2, i64 1
%14 = load i8*, i8** %13
%15 = tail call i8* @buffer_load(i8* %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i8* @xxstrdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = phi i8* [ %15, %12 ], [ %18, %17 ]
%21 = tail call i64 @strlen(i8* dereferenceable(1) %14)
%22 = tail call i64 @strlen(i8* dereferenceable(1) %20)
%23 = add i64 %21, 3
%24 = add i64 %23, %22
%25 = tail call i8* @malloc(i64 %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = tail call i32 @free(i8* %14)
%29 = tail call i32 @free(i8* %20)
br label %36
30: ; preds = %19
%31 = tail call i32 (i32, i32, i8*, ...) @ftsh_error(i32 20, i32 %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %14, i8* %20)
%32 = tail call i32 @sprintf(i8* %25, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %14, i8* %20)
%33 = tail call i32 @putenv(i8* %25)
%34 = tail call i32 @free(i8* %14)
%35 = tail call i32 @free(i8* %20)
br label %36
36: ; preds = %30, %27, %10, %6
%37 = phi i32 [ 0, %6 ], [ 0, %10 ], [ 1, %30 ], [ 0, %27 ]
ret i32 %37
}