#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 */
scalar_t__ change_path(char *, char **);
int /*<<< orphan*/ get_out(int /*<<< orphan*/);
int /*<<< orphan*/ len(char *);
int /*<<< orphan*/ my_atoi(char *);
char **set_environ(char *, char **);
scalar_t__ strn_cmp(char *, char *, int /*<<< orphan*/);
char **strto_wordtab(char *, char *);
char **unset_environ(char *, char **);
int built_in(char *user_input, char **environ) {
  char **args;
  args = strto_wordtab(user_input, " ");
  if ((strn_cmp(args[0], "exit", len(args[0]))))
    get_out(my_atoi(args[1]));
  if ((strn_cmp(args[0], "setenv", len(args[0])))) {
    if ((environ = set_environ(user_input, environ)))
      return (0);
    return (1);
  }
  if ((strn_cmp(args[0], "unsetenv", len(args[0])))) {
    if ((environ = unset_environ(user_input, environ)))
      return (0);
    return (1);
  }
  if ((strn_cmp(args[0], "cd", len(args[0])))) {
    if ((change_path(user_input, environ)))
      return (1);
    return (0);
  }
  return (1);
}


x86 assembly (clang, -O0):
<built_in>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1080 <strto_wordtab@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1050 <len@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe3a(%rip),%rsi
call   1040 <strn_cmp@plt>
cmp    $0x0,%rax
je     11eb <built_in+0x6b>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <my_atoi@plt>
mov    %eax,%edi
call   1060 <get_out@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1050 <len@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xdfa(%rip),%rsi
call   1040 <strn_cmp@plt>
cmp    $0x0,%rax
je     1251 <built_in+0xd1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <set_environ@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1245 <built_in+0xc5>
movl   $0x0,-0x4(%rbp)
jmp    1320 <built_in+0x1a0>
movl   $0x1,-0x4(%rbp)
jmp    1320 <built_in+0x1a0>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1050 <len@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xd92(%rip),%rsi
call   1040 <strn_cmp@plt>
cmp    $0x0,%rax
je     12b7 <built_in+0x137>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <unset_environ@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12ab <built_in+0x12b>
movl   $0x0,-0x4(%rbp)
jmp    1320 <built_in+0x1a0>
movl   $0x1,-0x4(%rbp)
jmp    1320 <built_in+0x1a0>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1050 <len@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
lea    0xd35(%rip),%rsi
call   1040 <strn_cmp@plt>
cmp    $0x0,%rax
je     1319 <built_in+0x199>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <change_path@plt>
cmp    $0x0,%rax
je     130d <built_in+0x18d>
movl   $0x1,-0x4(%rbp)
jmp    1320 <built_in+0x1a0>
movl   $0x0,-0x4(%rbp)
jmp    1320 <built_in+0x1a0>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<built_in>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe6b(%rip),%rsi
call   1080 <strto_wordtab@plt>
mov    %rax,%r12
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1050 <len@plt>
lea    0xe53(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <strn_cmp@plt>
test   %rax,%rax
je     11cf <built_in+0x4f>
mov    0x8(%r12),%rdi
call   1030 <my_atoi@plt>
mov    %eax,%edi
call   1060 <get_out@plt>
mov    (%r12),%rbx
mov    %rbx,%rdi
call   1050 <len@plt>
lea    0xe27(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <strn_cmp@plt>
test   %rax,%rax
je     11fe <built_in+0x7e>
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <set_environ@plt>
jmp    122b <built_in+0xab>
mov    (%r12),%rbx
mov    %rbx,%rdi
call   1050 <len@plt>
lea    0xdf6(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <strn_cmp@plt>
test   %rax,%rax
je     1240 <built_in+0xc0>
mov    %r15,%rdi
mov    %r14,%rsi
call   1090 <unset_environ@plt>
test   %rax,%rax
sete   %al
movzbl %al,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    (%r12),%rbx
mov    %rbx,%rdi
call   1050 <len@plt>
lea    0xdbd(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <strn_cmp@plt>
test   %rax,%rax
je     1275 <built_in+0xf5>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <change_path@plt>
test   %rax,%rax
setne  %al
jmp    1231 <built_in+0xb1>
mov    $0x1,%al
jmp    1231 <built_in+0xb1>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [7 x i8] c"setenv\00"
@.str.3 = [9 x i8] c"unsetenv\00"
@.str.4 = [3 x i8] c"cd\00"
define i32 @built_in(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8**
store i8* %0, i8** %4
store i8** %1, i8*** %5
%7 = load i8*, i8** %4
%8 = call i8** @strto_wordtab(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8** %8, i8*** %6
%9 = load i8**, i8*** %6
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = load i8**, i8*** %6
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @len(i8* %14)
%16 = call i64 @strn_cmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i8**, i8*** %6
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @my_atoi(i8* %21)
%23 = call i32 @get_out(i32 %22)
br label %24
24: ; preds = %18, %2
%25 = load i8**, i8*** %6
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %6
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @len(i8* %30)
%32 = call i64 @strn_cmp(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %24
%35 = load i8*, i8** %4
%36 = load i8**, i8*** %5
%37 = call i8** @set_environ(i8* %35, i8** %36)
store i8** %37, i8*** %5
%38 = icmp ne i8** %37, null
br i1 %38, label %39, label %40
39: ; preds = %34
store i32 0, i32* %3
br label %76
40: ; preds = %34
store i32 1, i32* %3
br label %76
41: ; preds = %24
%42 = load i8**, i8*** %6
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = load i8**, i8*** %6
%46 = getelementptr inbounds i8*, i8** %45, i64 0
%47 = load i8*, i8** %46
%48 = call i32 @len(i8* %47)
%49 = call i64 @strn_cmp(i8* %44, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %58
51: ; preds = %41
%52 = load i8*, i8** %4
%53 = load i8**, i8*** %5
%54 = call i8** @unset_environ(i8* %52, i8** %53)
store i8** %54, i8*** %5
%55 = icmp ne i8** %54, null
br i1 %55, label %56, label %57
56: ; preds = %51
store i32 0, i32* %3
br label %76
57: ; preds = %51
store i32 1, i32* %3
br label %76
58: ; preds = %41
%59 = load i8**, i8*** %6
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = load i8**, i8*** %6
%63 = getelementptr inbounds i8*, i8** %62, i64 0
%64 = load i8*, i8** %63
%65 = call i32 @len(i8* %64)
%66 = call i64 @strn_cmp(i8* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %75
68: ; preds = %58
%69 = load i8*, i8** %4
%70 = load i8**, i8*** %5
%71 = call i64 @change_path(i8* %69, i8** %70)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %74
73: ; preds = %68
store i32 1, i32* %3
br label %76
74: ; preds = %68
store i32 0, i32* %3
br label %76
75: ; preds = %58
store i32 1, i32* %3
br label %76
76: ; preds = %75, %74, %73, %57, %56, %40, %39
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [7 x i8] c"setenv\00"
@.str.3 = [9 x i8] c"unsetenv\00"
@.str.4 = [3 x i8] c"cd\00"
define i32 @built_in(i8* %0, i8** %1) {
%3 = tail call i8** @strto_wordtab(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = load i8*, i8** %3
%5 = tail call i32 @len(i8* %4)
%6 = tail call i64 @strn_cmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %3, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @my_atoi(i8* %10)
%12 = tail call i32 @get_out(i32 %11)
br label %13
13: ; preds = %8, %2
%14 = load i8*, i8** %3
%15 = tail call i32 @len(i8* %14)
%16 = tail call i64 @strn_cmp(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = tail call i8** @set_environ(i8* %0, i8** %1)
%20 = icmp eq i8** %19, null
br label %37
21: ; preds = %13
%22 = load i8*, i8** %3
%23 = tail call i32 @len(i8* %22)
%24 = tail call i64 @strn_cmp(i8* %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = tail call i8** @unset_environ(i8* %0, i8** %1)
%28 = icmp eq i8** %27, null
br label %37
29: ; preds = %21
%30 = load i8*, i8** %3
%31 = tail call i32 @len(i8* %30)
%32 = tail call i64 @strn_cmp(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %29
%35 = tail call i64 @change_path(i8* %0, i8** %1)
%36 = icmp ne i64 %35, 0
br label %37
37: ; preds = %29, %34, %26, %18
%38 = phi i1 [ %20, %18 ], [ %28, %26 ], [ %36, %34 ], [ true, %29 ]
%39 = zext i1 %38 to i32
ret i32 %39
}