#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 */
struct instrument {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int _docmd(struct instrument *, char **);
char **argv_create(char *, char *);
int /*<<< orphan*/ argv_destroy(char **);
scalar_t__ strlen(char *);
scalar_t__ xreadline(char *, char *, int);
void _shell(struct instrument *gd) {
  char buf[128];
  char **av;
  int rc = 0;
  while (rc == 0 && (xreadline("hp3488> ", buf, sizeof(buf)))) {
    if (strlen(buf) > 0) {
      av = argv_create(buf, "");
      rc = _docmd(gd, av);
      argv_destroy(av);
    }
  }
}


x86 assembly (clang, -O0):
<_shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x9c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x9c(%rbp)
mov    %al,-0x9d(%rbp)
jne    11a3 <_shell+0x53>
lea    -0x90(%rbp),%rsi
lea    0xe74(%rip),%rdi
mov    $0x80,%edx
call   1070 <xreadline@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x9d(%rbp)
mov    -0x9d(%rbp),%al
test   $0x1,%al
jne    11b6 <_shell+0x66>
jmp    120d <_shell+0xbd>
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jle    1208 <_shell+0xb8>
lea    -0x90(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1030 <argv_create@plt>
mov    %rax,-0x98(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x98(%rbp),%rsi
call   1060 <_docmd@plt>
mov    %eax,-0x9c(%rbp)
mov    -0x98(%rbp),%rdi
call   1040 <argv_destroy@plt>
jmp    1169 <_shell+0x19>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_shell>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%r15
lea    0xe95(%rip),%r14
mov    %rsp,%r13
lea    0xe93(%rip),%r12
jmp    1186 <_shell+0x36>
nopw   0x0(%rax,%rax,1)
xor    %ebp,%ebp
test   %ebp,%ebp
jne    11cf <_shell+0x7f>
mov    %r14,%rdi
mov    %r13,%rsi
mov    $0x80,%edx
call   1070 <xreadline@plt>
test   %rax,%rax
je     11cf <_shell+0x7f>
mov    %r13,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
jle    1180 <_shell+0x30>
mov    %r13,%rdi
mov    %r12,%rsi
call   1030 <argv_create@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1060 <_docmd@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <argv_destroy@plt>
test   %ebp,%ebp
je     1186 <_shell+0x36>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.instrument = type { i32 }
@.str = [9 x i8] c"hp3488> \00"
@.str.1 = [1 x i8] zeroinitializer
define void @_shell(%struct.instrument* %0) {
%2 = alloca %struct.instrument*
%3 = alloca [128 x i8]
%4 = alloca i8**
%5 = alloca i32
store %struct.instrument* %0, %struct.instrument** %2
store i32 0, i32* %5
br label %6
6: ; preds = %27, %1
%7 = load i32, i32* %5
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%11 = call i64 @xreadline(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %10, i32 128)
%12 = icmp ne i64 %11, 0
br label %13
13: ; preds = %9, %6
%14 = phi i1 [ false, %6 ], [ %12, %9 ]
br i1 %14, label %15, label %28
15: ; preds = %13
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%17 = call i64 @strlen(i8* %16)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%21 = call i8** @argv_create(i8* %20, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8** %21, i8*** %4
%22 = load %struct.instrument*, %struct.instrument** %2
%23 = load i8**, i8*** %4
%24 = call i32 @_docmd(%struct.instrument* %22, i8** %23)
store i32 %24, i32* %5
%25 = load i8**, i8*** %4
%26 = call i32 @argv_destroy(i8** %25)
br label %27
27: ; preds = %19, %15
br label %6
28: ; preds = %13
ret void
}

LLVM IR (-O2):
%struct.instrument = type { i32 }
@.str = [9 x i8] c"hp3488> \00"
@.str.1 = [1 x i8] zeroinitializer
define void @_shell(%struct.instrument* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %1, %14
%5 = call i64 @xreadline(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %3, i32 128)
%6 = icmp eq i64 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %4
%8 = call i64 @strlen(i8* %3)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = call i8** @argv_create(i8* %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @_docmd(%struct.instrument* %0, i8** %11)
%13 = call i32 @argv_destroy(i8** %11)
br label %14
14: ; preds = %10, %7
%15 = phi i32 [ %12, %10 ], [ 0, %7 ]
%16 = icmp eq i32 %15, 0
br i1 %16, label %4, label %17
17: ; preds = %14, %4
ret void
}