#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 ft_cmd_env_set(char *, char *);
int ft_cmd_env_show();
int ft_sh_error(char *);
size_t ft_sh_tablen(char **);
int /*<<< orphan*/ *ft_strchr(char *, char);
int ft_cmd_setenv(char **argv) {
  size_t argv_len;
  char *value;
  argv_len = ft_sh_tablen(argv);
  if (argv_len > 3)
    return (ft_sh_error("42sh: setenv: Too many arguments."));
  else if (argv_len <= 1)
    return (ft_cmd_env_show());
  value = (argv_len == 3 ? argv[2] : "\0");
  if (ft_strchr(argv[1], '=') != NULL)
    return (ft_sh_error("42sh: setenv: Syntax error."));
  return (ft_cmd_env_set(argv[1], value));
}


x86 assembly (clang, -O0):
<ft_cmd_setenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ft_sh_tablen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x3,-0x18(%rbp)
jbe    1188 <ft_cmd_setenv+0x38>
lea    0xe85(%rip),%rdi
call   1070 <ft_sh_error@plt>
mov    %eax,-0x4(%rbp)
jmp    121f <ft_cmd_setenv+0xcf>
cmpq   $0x1,-0x18(%rbp)
ja     11a2 <ft_cmd_setenv+0x52>
mov    $0x0,%al
call   1050 <ft_cmd_env_show@plt>
mov    %eax,-0x4(%rbp)
jmp    121f <ft_cmd_setenv+0xcf>
jmp    11a7 <ft_cmd_setenv+0x57>
cmpq   $0x3,-0x18(%rbp)
jne    11c3 <ft_cmd_setenv+0x73>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    11d3 <ft_cmd_setenv+0x83>
lea    0xe74(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11d3 <ft_cmd_setenv+0x83>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x3d,%esi
call   1060 <ft_strchr@plt>
cmp    $0x0,%rax
je     120b <ft_cmd_setenv+0xbb>
lea    0xe24(%rip),%rdi
call   1070 <ft_sh_error@plt>
mov    %eax,-0x4(%rbp)
jmp    121f <ft_cmd_setenv+0xcf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <ft_cmd_env_set@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_cmd_setenv>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <ft_sh_tablen@plt>
cmp    $0x4,%rax
jb     116b <ft_cmd_setenv+0x1b>
lea    0xe97(%rip),%rdi
jmp    11ac <ft_cmd_setenv+0x5c>
cmp    $0x1,%rax
ja     117f <ft_cmd_setenv+0x2f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <ft_cmd_env_show@plt>
cmp    $0x3,%rax
jne    118b <ft_cmd_setenv+0x3b>
mov    0x10(%rbx),%r14
jmp    1192 <ft_cmd_setenv+0x42>
lea    0xeac(%rip),%r14
mov    0x8(%rbx),%rdi
mov    $0x3d,%esi
call   1060 <ft_strchr@plt>
test   %rax,%rax
je     11b8 <ft_cmd_setenv+0x68>
lea    0xe76(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <ft_sh_error@plt>
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <ft_cmd_env_set@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"42sh: setenv: Too many arguments.\00"
@.str.1 = [2 x i8] zeroinitializer
@.str.2 = [28 x i8] c"42sh: setenv: Syntax error.\00"
define i32 @ft_cmd_setenv(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i64
%5 = alloca i8*
store i8** %0, i8*** %3
%6 = load i8**, i8*** %3
%7 = call i64 @ft_sh_tablen(i8** %6)
store i64 %7, i64* %4
%8 = load i64, i64* %4
%9 = icmp ugt i64 %8, 3
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @ft_sh_error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %2
br label %41
12: ; preds = %1
%13 = load i64, i64* %4
%14 = icmp ule i64 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 (...) @ft_cmd_env_show()
store i32 %16, i32* %2
br label %41
17: ; preds = %12
br label %18
18: ; preds = %17
%19 = load i64, i64* %4
%20 = icmp eq i64 %19, 3
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i8**, i8*** %3
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
br label %26
25: ; preds = %18
br label %26
26: ; preds = %25, %21
%27 = phi i8* [ %24, %21 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %25 ]
store i8* %27, i8** %5
%28 = load i8**, i8*** %3
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32* @ft_strchr(i8* %30, i8 signext 61)
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @ft_sh_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 %34, i32* %2
br label %41
35: ; preds = %26
%36 = load i8**, i8*** %3
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = load i8*, i8** %5
%40 = call i32 @ft_cmd_env_set(i8* %38, i8* %39)
store i32 %40, i32* %2
br label %41
41: ; preds = %35, %33, %15, %10
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str = [34 x i8] c"42sh: setenv: Too many arguments.\00"
@.str.1 = [2 x i8] zeroinitializer
@.str.2 = [28 x i8] c"42sh: setenv: Syntax error.\00"
define i32 @ft_cmd_setenv(i8** %0) {
%2 = tail call i64 @ft_sh_tablen(i8** %0)
%3 = icmp ugt i64 %2, 3
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @ft_sh_error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %26
6: ; preds = %1
%7 = icmp ult i64 %2, 2
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 (...) @ft_cmd_env_show()
br label %26
10: ; preds = %6
%11 = icmp eq i64 %2, 3
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = getelementptr inbounds i8*, i8** %0, i64 2
%14 = load i8*, i8** %13
br label %15
15: ; preds = %10, %12
%16 = phi i8* [ %14, %12 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %10 ]
%17 = getelementptr inbounds i8*, i8** %0, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32* @ft_strchr(i8* %18, i8 signext 61)
%20 = icmp eq i32* %19, null
br i1 %20, label %23, label %21
21: ; preds = %15
%22 = tail call i32 @ft_sh_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %26
23: ; preds = %15
%24 = load i8*, i8** %17
%25 = tail call i32 @ft_cmd_env_set(i8* %24, i8* %16)
br label %26
26: ; preds = %23, %21, %8, %4
%27 = phi i32 [ %5, %4 ], [ %9, %8 ], [ %22, %21 ], [ %25, %23 ]
ret i32 %27
}