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


x86 assembly (clang, -O0):
<built_in>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe75(%rip),%rdi
mov    $0x4,%edx
call   1040 <strn_cmp@plt>
cmp    $0x0,%rax
je     11cc <built_in+0x5c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe52(%rip),%rdi
call   1050 <len@plt>
mov    -0x20(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0x1,%rdi
call   1030 <my_atoi@plt>
mov    %eax,%edi
call   1060 <get_out@plt>
mov    -0x10(%rbp),%rsi
lea    0xe30(%rip),%rdi
mov    $0x6,%edx
call   1040 <strn_cmp@plt>
cmp    $0x0,%rax
je     121e <built_in+0xae>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <set_environ@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1212 <built_in+0xa2>
movl   $0x0,-0x4(%rbp)
jmp    12c5 <built_in+0x155>
movl   $0x1,-0x4(%rbp)
jmp    12c5 <built_in+0x155>
mov    -0x10(%rbp),%rsi
lea    0xddc(%rip),%rdi
mov    $0x8,%edx
call   1040 <strn_cmp@plt>
cmp    $0x0,%rax
je     1270 <built_in+0x100>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <unset_environ@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1264 <built_in+0xf4>
movl   $0x0,-0x4(%rbp)
jmp    12c5 <built_in+0x155>
movl   $0x1,-0x4(%rbp)
jmp    12c5 <built_in+0x155>
mov    -0x10(%rbp),%rsi
lea    0xd93(%rip),%rdi
mov    $0x2,%edx
call   1040 <strn_cmp@plt>
cmp    $0x0,%rax
je     12be <built_in+0x14e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <change_path@plt>
cmp    $0x0,%rax
je     12b2 <built_in+0x142>
movl   $0x1,-0x4(%rbp)
jmp    12c5 <built_in+0x155>
movl   $0x0,-0x4(%rbp)
jmp    12c5 <built_in+0x155>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<built_in>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe7f(%rip),%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <strn_cmp@plt>
test   %rax,%rax
je     11b5 <built_in+0x45>
lea    0xe66(%rip),%rdi
call   1050 <len@plt>
cltq
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1030 <my_atoi@plt>
mov    %eax,%edi
call   1060 <get_out@plt>
lea    0xe4b(%rip),%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1040 <strn_cmp@plt>
test   %rax,%rax
je     11db <built_in+0x6b>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <set_environ@plt>
jmp    11ff <built_in+0x8f>
lea    0xe23(%rip),%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1040 <strn_cmp@plt>
test   %rax,%rax
je     1210 <built_in+0xa0>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <unset_environ@plt>
test   %rax,%rax
sete   %al
movzbl %al,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdf7(%rip),%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1040 <strn_cmp@plt>
test   %rax,%rax
je     123c <built_in+0xcc>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <change_path@plt>
test   %rax,%rax
setne  %al
jmp    1205 <built_in+0x95>
mov    $0x1,%al
jmp    1205 <built_in+0x95>

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

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