#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int errno;
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int run_cmd(int, char const **);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char const *, char *);
char *strsep(char **, char *);
int /*<<< orphan*/ warn(char *);
int run_cmd_loop(void) {
  int i, rc = 0;
  char buffer[128], *buf;
  const char *args[15 + 1];
  for (;;) {
    fprintf(stdout, "> ");
    fflush(stdout);
    buf = fgets(buffer, sizeof(buffer), stdin);
    if (buf == NULL) {
      if (ferror(stdin)) {
        warn("stdin error");
        rc = errno;
      }
      break;
    }
    i = 0;
    while ((args[i] = strsep(&buf, " \t\n")) != NULL) {
      if (args[i][0] != 0 && ++i == 15)
        break;
    }
    args[i] = 0;
    if (i == 0)
      continue;
    if (!strcmp(args[0], "quit") || !strcmp(args[0], "exit"))
      break;
    rc = run_cmd(i, args);
  }
  return (rc);
}


x86 assembly (clang, -O0):
<run_cmd_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x8(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
lea    -0x90(%rbp),%rdi
mov    0x2e25(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1050 <fgets@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    1219 <run_cmd_loop+0x99>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1214 <run_cmd_loop+0x94>
lea    0xe00(%rip),%rdi
call   1030 <warn@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    12f0 <run_cmd_loop+0x170>
movl   $0x0,-0x4(%rbp)
lea    -0x98(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   1090 <strsep@plt>
movslq -0x4(%rbp),%rcx
mov    %rax,-0x120(%rbp,%rcx,8)
ff
cmp    $0x0,%rax
je     127d <run_cmd_loop+0xfd>
movslq -0x4(%rbp),%rax
mov    -0x120(%rbp,%rax,8),%rax
ff
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1278 <run_cmd_loop+0xf8>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
cmp    $0xf,%eax
jne    1278 <run_cmd_loop+0xf8>
jmp    127d <run_cmd_loop+0xfd>
jmp    1220 <run_cmd_loop+0xa0>
movslq -0x4(%rbp),%rax
movq   $0x0,-0x120(%rbp,%rax,8)
cmpl   $0x0,-0x4(%rbp)
jne    129c <run_cmd_loop+0x11c>
jmp    1192 <run_cmd_loop+0x12>
mov    -0x120(%rbp),%rdi
lea    0xd69(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     12d4 <run_cmd_loop+0x154>
mov    -0x120(%rbp),%rdi
lea    0xd52(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12d9 <run_cmd_loop+0x159>
jmp    12f0 <run_cmd_loop+0x170>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
call   10a0 <run_cmd@plt>
mov    %eax,-0x8(%rbp)
jmp    1192 <run_cmd_loop+0x12>
mov    -0x8(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_cmd_loop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
movl   $0x0,0x4(%rsp)
mov    0x2e30(%rip),%r15
lea    0xe59(%rip),%r14
mov    0x2e3a(%rip),%r12
lea    0xe5a(%rip),%rbx
lea    0x8(%rsp),%rbp
jmp    11d4 <run_cmd_loop+0x54>
nopl   0x0(%rax)
movslq %r13d,%rax
movq   $0x0,0x10(%rsp,%rax,8)
test   %eax,%eax
jne    1259 <run_cmd_loop+0xd9>
mov    (%r15),%edi
mov    %r14,%rsi
call   1070 <fprintf@plt>
mov    (%r15),%edi
call   1080 <fflush@plt>
mov    (%r12),%edx
lea    0x90(%rsp),%rdi
mov    $0x80,%esi
call   1050 <fgets@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     12ad <run_cmd_loop+0x12d>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1090 <strsep@plt>
mov    %rax,0x10(%rsp)
xor    %r13d,%r13d
jmp    1233 <run_cmd_loop+0xb3>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1090 <strsep@plt>
movslq %r13d,%rcx
mov    %rax,0x10(%rsp,%rcx,8)
test   %rax,%rax
je     11c0 <run_cmd_loop+0x40>
cmpb   $0x0,(%rax)
je     1220 <run_cmd_loop+0xa0>
add    $0x1,%r13d
cmp    $0xf,%r13d
jne    1220 <run_cmd_loop+0xa0>
movq   $0x0,0x88(%rsp)
mov    $0xf,%r13d
mov    %r12,%r15
mov    %r14,%r12
mov    0x10(%rsp),%r14
mov    %r14,%rdi
lea    0xda5(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     12d4 <run_cmd_loop+0x154>
mov    %r14,%rdi
lea    0xd97(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     12d4 <run_cmd_loop+0x154>
mov    %r13d,%edi
lea    0x10(%rsp),%rsi
call   10a0 <run_cmd@plt>
mov    %eax,0x4(%rsp)
mov    %r12,%r14
mov    %r15,%r12
mov    0x2d28(%rip),%r15
jmp    11d4 <run_cmd_loop+0x54>
mov    (%r12),%edi
call   1040 <ferror@plt>
test   %rax,%rax
je     12d4 <run_cmd_loop+0x154>
lea    0xd41(%rip),%rdi
call   1030 <warn@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x4(%rsp),%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.1 = [12 x i8] c"stdin error\00"
@errno = global i32 0
@.str.2 = [4 x i8] c" \09\0A\00"
@.str.3 = [5 x i8] c"quit\00"
@.str.4 = [5 x i8] c"exit\00"
define i32 @run_cmd_loop() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = alloca i8*
%5 = alloca [16 x i8*]
store i32 0, i32* %2
br label %6
6: ; preds = %64, %52, %0
%7 = load i32, i32* @stdout
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stdout
%10 = call i32 @fflush(i32 %9)
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i8* @fgets(i8* %11, i32 128, i32 %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %24
16: ; preds = %6
%17 = load i32, i32* @stdin
%18 = call i64 @ferror(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = call i32 @warn(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @errno
store i32 %22, i32* %2
br label %23
23: ; preds = %20, %16
br label %68
24: ; preds = %6
store i32 0, i32* %1
br label %25
25: ; preds = %45, %24
%26 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* %1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [16 x i8*], [16 x i8*]* %5, i64 0, i64 %28
store i8* %26, i8** %29
%30 = icmp ne i8* %26, null
br i1 %30, label %31, label %46
31: ; preds = %25
%32 = load i32, i32* %1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [16 x i8*], [16 x i8*]* %5, i64 0, i64 %33
%35 = load i8*, i8** %34
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %31
%41 = load i32, i32* %1
%42 = add nsw i32 %41, 1
store i32 %42, i32* %1
%43 = icmp eq i32 %42, 15
br i1 %43, label %44, label %45
44: ; preds = %40
br label %46
45: ; preds = %40, %31
br label %25
46: ; preds = %44, %25
%47 = load i32, i32* %1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [16 x i8*], [16 x i8*]* %5, i64 0, i64 %48
store i8* null, i8** %49
%50 = load i32, i32* %1
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %46
br label %6
53: ; preds = %46
%54 = getelementptr inbounds [16 x i8*], [16 x i8*]* %5, i64 0, i64 0
%55 = load i8*, i8** %54
%56 = call i32 @strcmp(i8* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %53
%59 = getelementptr inbounds [16 x i8*], [16 x i8*]* %5, i64 0, i64 0
%60 = load i8*, i8** %59
%61 = call i32 @strcmp(i8* %60, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%62 = icmp ne i32 %61, 0
br i1 %62, label %64, label %63
63: ; preds = %58, %53
br label %68
64: ; preds = %58
%65 = load i32, i32* %1
%66 = getelementptr inbounds [16 x i8*], [16 x i8*]* %5, i64 0, i64 0
%67 = call i32 @run_cmd(i32 %65, i8** %66)
store i32 %67, i32* %2
br label %6
68: ; preds = %63, %23
%69 = load i32, i32* %2
ret i32 %69
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.1 = [12 x i8] c"stdin error\00"
@errno = global i32 0
@.str.2 = [4 x i8] c" \09\0A\00"
@.str.3 = [5 x i8] c"quit\00"
@.str.4 = [5 x i8] c"exit\00"
define i32 @run_cmd_loop() {
%1 = alloca [128 x i8]
%2 = alloca i8*
%3 = alloca [16 x i8*]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%5 = bitcast i8** %2 to i8*
%6 = bitcast [16 x i8*]* %3 to i8*
%7 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 15
br label %9
9: ; preds = %57, %0
%10 = phi i32 [ %58, %57 ], [ 0, %0 ]
br label %11
11: ; preds = %9, %44
%12 = load i32, i32* @stdout
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @stdout
%15 = call i32 @fflush(i32 %14)
%16 = load i32, i32* @stdin
%17 = call i8* @fgets(i8* %4, i32 128, i32 %16)
store i8* %17, i8** %2
%18 = icmp eq i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %11
%20 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i8* %20, i8** %7
%21 = icmp eq i8* %20, null
br i1 %21, label %44, label %29
22: ; preds = %11
%23 = load i32, i32* @stdin
%24 = call i64 @ferror(i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %59, label %26
26: ; preds = %22
%27 = call i32 @warn(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @errno
br label %59
29: ; preds = %19, %38
%30 = phi i8* [ %40, %38 ], [ %20, %19 ]
%31 = phi i32 [ %39, %38 ], [ 0, %19 ]
%32 = load i8, i8* %30
%33 = icmp eq i8 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %29
%35 = add nsw i32 %31, 1
%36 = icmp eq i32 %35, 15
br i1 %36, label %37, label %38
37: ; preds = %34
store i8* null, i8** %8
br label %49
38: ; preds = %34, %29
%39 = phi i32 [ %35, %34 ], [ %31, %29 ]
%40 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 %41
store i8* %40, i8** %42
%43 = icmp eq i8* %40, null
br i1 %43, label %44, label %29
44: ; preds = %38, %19
%45 = phi i32 [ 0, %19 ], [ %39, %38 ]
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 %46
store i8* null, i8** %47
%48 = icmp eq i32 %45, 0
br i1 %48, label %11, label %49
49: ; preds = %44, %37
%50 = phi i32 [ 15, %37 ], [ %45, %44 ]
%51 = load i8*, i8** %7
%52 = call i32 @strcmp(i8* dereferenceable(1) %51, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%53 = icmp eq i32 %52, 0
br i1 %53, label %59, label %54
54: ; preds = %49
%55 = call i32 @strcmp(i8* dereferenceable(1) %51, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%56 = icmp eq i32 %55, 0
br i1 %56, label %59, label %57
57: ; preds = %54
%58 = call i32 @run_cmd(i32 %50, i8** %7)
br label %9
59: ; preds = %49, %54, %22, %26
%60 = phi i32 [ %28, %26 ], [ %10, %22 ], [ %10, %54 ], [ %10, %49 ]
ret i32 %60
}