#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 /*<<< orphan*/ shell_process_command(char *);
int shell_update_buffer(char *buffer, int *index, char key) {
  if (key == '\n') {
    shell_process_command(buffer);
    return 1;
  }
  if (*index < 255) {
    buffer[*index] = key;
    index[0]++;
    buffer[*index] = '\0';
  }
  return 0;
}


x86 assembly (clang, -O0):
<shell_update_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    1147 <shell_update_buffer+0x37>
mov    -0x10(%rbp),%rdi
call   1030 <shell_process_command@plt>
movl   $0x1,-0x4(%rbp)
jmp    1189 <shell_update_buffer+0x79>
mov    -0x18(%rbp),%rax
cmpl   $0xff,(%rax)
jge    1182 <shell_update_buffer+0x72>
mov    -0x19(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shell_update_buffer>:
push   %rax
cmp    $0xa,%dl
jne    1122 <shell_update_buffer+0x12>
call   1030 <shell_process_command@plt>
mov    $0x1,%eax
pop    %rcx
ret
movslq (%rsi),%rcx
xor    %eax,%eax
cmp    $0xfe,%rcx
jg     1141 <shell_update_buffer+0x31>
mov    %dl,(%rdi,%rcx,1)
movslq (%rsi),%rcx
lea    0x1(%rcx),%rdx
mov    %edx,(%rsi)
movb   $0x0,0x1(%rdi,%rcx,1)
pop    %rcx
ret

LLVM IR (-O0):
define i32 @shell_update_buffer(i8* %0, i32* %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8
store i8* %0, i8** %5
store i32* %1, i32** %6
store i8 %2, i8* %7
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 10
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = call i32 @shell_process_command(i8* %12)
store i32 1, i32* %4
br label %35
14: ; preds = %3
%15 = load i32*, i32** %6
%16 = load i32, i32* %15
%17 = icmp slt i32 %16, 255
br i1 %17, label %18, label %34
18: ; preds = %14
%19 = load i8, i8* %7
%20 = load i8*, i8** %5
%21 = load i32*, i32** %6
%22 = load i32, i32* %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 %19, i8* %24
%25 = load i32*, i32** %6
%26 = getelementptr inbounds i32, i32* %25, i64 0
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
store i32 %28, i32* %26
%29 = load i8*, i8** %5
%30 = load i32*, i32** %6
%31 = load i32, i32* %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %18, %14
store i32 0, i32* %4
br label %35
35: ; preds = %34, %11
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
define i32 @shell_update_buffer(i8* %0, i32* nocapture %1, i8 signext %2) {
%4 = icmp eq i8 %2, 10
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @shell_process_command(i8* %0)
br label %17
7: ; preds = %3
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 255
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = sext i32 %8 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 %2, i8* %12
%13 = load i32, i32* %1
%14 = add nsw i32 %13, 1
store i32 %14, i32* %1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 0, i8* %16
br label %17
17: ; preds = %7, %10, %5
%18 = phi i32 [ 1, %5 ], [ 0, %10 ], [ 0, %7 ]
ret i32 %18
}