#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 strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int builtin_command(char *input_buffer, int *parameters_index) {
  if (!strncmp(input_buffer, "cd", strlen("cd")) &&
      input_buffer[strlen("cd") == ' ']) {
    *parameters_index = strlen("cd") + 1;
    return 0;
  } else if (!strncmp(input_buffer, "history", strlen("history"))) {
    *parameters_index = -1;
    return 1;
  } else if (!strncmp(input_buffer, "!", strlen("!"))) {
    *parameters_index = strlen("!");
    return 2;
  } else {
    *parameters_index = -1;
    return -1;
  }
}


x86 assembly (clang, -O0):
<builtin_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xec1(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xeaf(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11b8 <builtin_command+0x98>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe92(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
cmp    $0x20,%ecx
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11b8 <builtin_command+0x98>
lea    0xe64(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    125d <builtin_command+0x13d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe3c(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xe2a(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11fd <builtin_command+0xdd>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    125d <builtin_command+0x13d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xdff(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xded(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    124c <builtin_command+0x12c>
lea    0xdd8(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x2,-0x4(%rbp)
jmp    125d <builtin_command+0x13d>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<builtin_command>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xece(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11aa <builtin_command+0x8a>
lea    0xeb1(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11d8 <builtin_command+0xb8>
lea    0xe99(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    %eax,%edx
mov    $0xffffffff,%eax
mov    $0xffffffff,%ecx
test   %edx,%edx
jne    11e2 <builtin_command+0xc2>
lea    0xe6d(%rip),%rdi
call   1040 <strlen@plt>
mov    $0x2,%ecx
jmp    11e2 <builtin_command+0xc2>
lea    0xe4f(%rip),%rdi
call   1040 <strlen@plt>
xor    %ecx,%ecx
cmp    $0x20,%eax
sete   %cl
cmpb   $0x0,(%r15,%rcx,1)
je     114b <builtin_command+0x2b>
lea    0xe34(%rip),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
xor    %ecx,%ecx
jmp    11e2 <builtin_command+0xc2>
mov    $0x1,%ecx
mov    $0xffffffff,%eax
mov    %eax,(%r14)
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"cd\00"
@.str.1 = [8 x i8] c"history\00"
@.str.2 = [2 x i8] c"!\00"
define i32 @builtin_command(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
%6 = load i8*, i8** %4
%7 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @strncmp(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %24, label %10
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32 %12, 32
%14 = zext i1 %13 to i32
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %11, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %10
%21 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = add nsw i32 %21, 1
%23 = load i32*, i32** %5
store i32 %22, i32* %23
store i32 0, i32* %3
br label %41
24: ; preds = %10, %2
%25 = load i8*, i8** %4
%26 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @strncmp(i8* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %24
%30 = load i32*, i32** %5
store i32 -1, i32* %30
store i32 1, i32* %3
br label %41
31: ; preds = %24
%32 = load i8*, i8** %4
%33 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @strncmp(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %31
%37 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32*, i32** %5
store i32 %37, i32* %38
store i32 2, i32* %3
br label %41
39: ; preds = %31
%40 = load i32*, i32** %5
store i32 -1, i32* %40
store i32 -1, i32* %3
br label %41
41: ; preds = %39, %36, %29, %20
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [3 x i8] c"cd\00"
@.str.1 = [8 x i8] c"history\00"
@.str.2 = [2 x i8] c"!\00"
define i32 @builtin_command(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %16
6: ; preds = %2
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, 32
%9 = zext i1 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %6
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = add nsw i32 %14, 1
br label %26
16: ; preds = %6, %2
%17 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %16
%21 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %20, %16, %24, %13
%27 = phi i32 [ %25, %24 ], [ %15, %13 ], [ -1, %16 ], [ -1, %20 ]
%28 = phi i32 [ 2, %24 ], [ 0, %13 ], [ 1, %16 ], [ -1, %20 ]
store i32 %27, i32* %1
ret i32 %28
}