#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 */
char EOF;
char getchar();
int /*<<< orphan*/ printf(char *, char *);
int nxtcmd(char *cmd, char *prompt) {
  int past, cnt;
  printf("%s ", prompt);
  past = 0;
  cnt = 0;
  while (1) {
    *cmd = getchar();
    if (*cmd == EOF)
      return (-1);
    if (*cmd == '\n') {
      *cmd = '\0';
      return (cnt);
    }
    if (past || *cmd != ' ') {
      cmd++;
      cnt++;
      past = 1;
    }
  }
}


x86 assembly (clang, -O0):
<nxtcmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xec5(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    0x2e7d(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1182 <nxtcmd+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <nxtcmd+0xbf>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11a4 <nxtcmd+0x84>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11df <nxtcmd+0xbf>
cmpl   $0x0,-0x1c(%rbp)
jne    11be <nxtcmd+0x9e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     11da <nxtcmd+0xba>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    114e <nxtcmd+0x2e>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nxtcmd>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
lea    0xece(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %al,(%r15)
mov    0x2ea0(%rip),%r14
cmp    (%r14),%al
je     118c <nxtcmd+0x6c>
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%al
je     1193 <nxtcmd+0x73>
test   %ebx,%ebx
setne  %cl
cmp    $0x20,%al
setne  %al
or     %cl,%al
movzbl %al,%ebx
lea    (%r15,%rbx,1),%r12
add    %ebx,%ebp
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %al,(%r15,%rbx,1)
mov    %r12,%r15
cmp    (%r14),%al
jne    1160 <nxtcmd+0x40>
mov    $0xffffffff,%ebp
jmp    1197 <nxtcmd+0x77>
movb   $0x0,(%r15)
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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