#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 find_inenv(char **, char *);
char *my_strcat(char *, char *);
char **strto_wordtab(char *, char *);
char **set_environ(char *buff, char **environ) {
  static int i = 0;
  char *tmp;
  char **buffer;
  buffer = strto_wordtab(buff, " ");
  if (!(buffer[2]))
    return (environ);
  tmp = my_strcat(buffer[1], "=");
  i = find_inenv(environ, buffer[1]);
  if (!(i)) {
    while (environ[i])
      i++;
  }
  environ[i] = my_strcat(tmp, buffer[2]);
  environ[i + 1] = 0;
  return (environ);
}


x86 assembly (clang, -O0):
<set_environ>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <strto_wordtab@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x10(%rax)
jne    1170 <set_environ+0x40>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1223 <set_environ+0xf3>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe83(%rip),%rsi
call   1040 <my_strcat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <find_inenv@plt>
mov    %eax,0x2e9d(%rip)
cmpl   $0x0,0x2e96(%rip)
jne    11e0 <set_environ+0xb0>
jmp    11b1 <set_environ+0x81>
mov    -0x18(%rbp),%rax
movslq 0x2e80(%rip),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11db <set_environ+0xab>
mov    0x2e6f(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e66(%rip)
jmp    11b1 <set_environ+0x81>
jmp    11e0 <set_environ+0xb0>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rsi
call   1040 <my_strcat@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq 0x2e3d(%rip),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    0x2e2f(%rip),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_environ>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
lea    0xec1(%rip),%rsi
call   1050 <strto_wordtab@plt>
cmpq   $0x0,0x10(%rax)
je     11b2 <set_environ+0x82>
mov    %rax,%r14
mov    0x8(%rax),%rdi
lea    0xea9(%rip),%rsi
call   1040 <my_strcat@plt>
mov    %rax,%r15
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
call   1030 <find_inenv@plt>
mov    %eax,0x2ec9(%rip)
test   %eax,%eax
jne    1192 <set_environ+0x62>
cmpq   $0x0,(%rbx)
je     1192 <set_environ+0x62>
xor    %eax,%eax
nop
cmpq   $0x0,0x8(%rbx,%rax,8)
lea    0x1(%rax),%rax
jne    1180 <set_environ+0x50>
mov    %eax,0x2eaa(%rip)
mov    0x10(%r14),%rsi
mov    %r15,%rdi
call   1040 <my_strcat@plt>
movslq 0x2e97(%rip),%rcx
mov    %rax,(%rbx,%rcx,8)
movq   $0x0,0x8(%rbx,%rcx,8)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@set_environ.i = internal global i32 0
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"=\00"
define i8** @set_environ(i8* %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8**
store i8* %0, i8** %4
store i8** %1, i8*** %5
%8 = load i8*, i8** %4
%9 = call i8** @strto_wordtab(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8** %9, i8*** %7
%10 = load i8**, i8*** %7
%11 = getelementptr inbounds i8*, i8** %10, i64 2
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = load i8**, i8*** %5
store i8** %15, i8*** %3
br label %56
16: ; preds = %2
%17 = load i8**, i8*** %7
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i8* @my_strcat(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %20, i8** %6
%21 = load i8**, i8*** %5
%22 = load i8**, i8*** %7
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @find_inenv(i8** %21, i8* %24)
store i32 %25, i32* @set_environ.i
%26 = load i32, i32* @set_environ.i
%27 = icmp ne i32 %26, 0
br i1 %27, label %40, label %28
28: ; preds = %16
br label %29
29: ; preds = %36, %28
%30 = load i8**, i8*** %5
%31 = load i32, i32* @set_environ.i
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %39
36: ; preds = %29
%37 = load i32, i32* @set_environ.i
%38 = add nsw i32 %37, 1
store i32 %38, i32* @set_environ.i
br label %29
39: ; preds = %29
br label %40
40: ; preds = %39, %16
%41 = load i8*, i8** %6
%42 = load i8**, i8*** %7
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i8* @my_strcat(i8* %41, i8* %44)
%46 = load i8**, i8*** %5
%47 = load i32, i32* @set_environ.i
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %46, i64 %48
store i8* %45, i8** %49
%50 = load i8**, i8*** %5
%51 = load i32, i32* @set_environ.i
%52 = add nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %50, i64 %53
store i8* null, i8** %54
%55 = load i8**, i8*** %5
store i8** %55, i8*** %3
br label %56
56: ; preds = %40, %14
%57 = load i8**, i8*** %3
ret i8** %57
}

LLVM IR (-O2):
@set_environ.i = internal unnamed_addr global i32 0
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"=\00"
define i8** @set_environ(i8* %0, i8** returned %1) {
%3 = tail call i8** @strto_wordtab(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds i8*, i8** %3, i64 2
%5 = load i8*, i8** %4
%6 = icmp eq i8* %5, null
br i1 %6, label %34, label %7
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %3, i64 1
%9 = load i8*, i8** %8
%10 = tail call i8* @my_strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = load i8*, i8** %8
%12 = tail call i32 @find_inenv(i8** %1, i8* %11)
store i32 %12, i32* @set_environ.i
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %7
%15 = load i8*, i8** %1
%16 = icmp eq i8* %15, null
br i1 %16, label %25, label %17
17: ; preds = %14, %17
%18 = phi i64 [ %19, %17 ], [ 0, %14 ]
%19 = add i64 %18, 1
%20 = getelementptr inbounds i8*, i8** %1, i64 %19
%21 = load i8*, i8** %20
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %17
23: ; preds = %17
%24 = trunc i64 %19 to i32
store i32 %24, i32* @set_environ.i
br label %25
25: ; preds = %14, %23, %7
%26 = load i8*, i8** %4
%27 = tail call i8* @my_strcat(i8* %10, i8* %26)
%28 = load i32, i32* @set_environ.i
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %1, i64 %29
store i8* %27, i8** %30
%31 = add nsw i32 %28, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %1, i64 %32
store i8* null, i8** %33
br label %34
34: ; preds = %2, %25
ret i8** %1
}