#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*/ add_cmd_char(char);
int /*<<< orphan*/ add_cmd_str(char *);
int findaction(char *);
int /*<<< orphan*/ lkerr(char *);
char *skipnsp(char *);
char *skipsp(char *);
scalar_t__ strlen(char *);
char *tstr(char **, int);
void parse_cmdline(char *p) {
  int cmdlen;
  char *actname;
  int action;
  char *s;
  char c;
  cmdlen = 0;
  do {
    s = tstr(&p, 1);
    cmdlen += strlen(s);
    if (cmdlen > 16)
      lkerr("command too long");
    else
      add_cmd_str(s);
  } while (*p != ' ' && *p != '\t' && *p != '\0');
  add_cmd_char('\0');
  p = skipsp(p);
  if (*p == '\0') {
    lkerr("missing action");
    return;
  }
  actname = p;
  p = skipnsp(p);
  c = *p;
  *p = '\0';
  action = findaction(actname);
  *p = c;
  p = skipsp(p);
  if (*p == '\0') {
    add_cmd_char(action);
  } else {
    add_cmd_char(action | 0200);
    while (*p != '\0')
      add_cmd_str(tstr(&p, 0));
    add_cmd_char('\0');
  }
}


x86 assembly (clang, -O0):
<parse_cmdline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   10a0 <tstr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
cmpl   $0x10,-0xc(%rbp)
jle    11d6 <parse_cmdline+0x56>
lea    0xe34(%rip),%rdi
call   1070 <lkerr@plt>
jmp    11df <parse_cmdline+0x5f>
mov    -0x28(%rbp),%rdi
call   1060 <add_cmd_str@plt>
jmp    11e4 <parse_cmdline+0x64>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x2a(%rbp)
je     121e <parse_cmdline+0x9e>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x9,%ecx
mov    %al,-0x2a(%rbp)
je     121e <parse_cmdline+0x9e>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
test   $0x1,%al
jne    1193 <parse_cmdline+0x13>
xor    %edi,%edi
call   1080 <add_cmd_char@plt>
mov    -0x8(%rbp),%rdi
call   1090 <skipsp@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    125e <parse_cmdline+0xde>
lea    0xdbd(%rip),%rdi
call   1070 <lkerr@plt>
jmp    1304 <parse_cmdline+0x184>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <skipnsp@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <findaction@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x29(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rdi
call   1090 <skipsp@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12c5 <parse_cmdline+0x145>
mov    -0x1c(%rbp),%eax
movsbl %al,%edi
call   1080 <add_cmd_char@plt>
jmp    1304 <parse_cmdline+0x184>
mov    -0x1c(%rbp),%eax
or     $0x80,%eax
movsbl %al,%edi
call   1080 <add_cmd_char@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12fd <parse_cmdline+0x17d>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
call   10a0 <tstr@plt>
mov    %rax,%rdi
call   1060 <add_cmd_str@plt>
jmp    12d5 <parse_cmdline+0x155>
xor    %edi,%edi
call   1080 <add_cmd_char@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_cmdline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,(%rsp)
xor    %ebx,%ebx
mov    %rsp,%r15
lea    0xe65(%rip),%r14
movabs $0x100000201,%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    $0x1,%esi
call   10a0 <tstr@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1040 <strlen@plt>
movslq %ebx,%rbx
add    %rax,%rbx
cmp    $0x11,%ebx
jl     11e0 <parse_cmdline+0x60>
mov    %r14,%rdi
call   1070 <lkerr@plt>
jmp    11e8 <parse_cmdline+0x68>
nopl   (%rax)
mov    %r12,%rdi
call   1060 <add_cmd_str@plt>
mov    (%rsp),%rax
movzbl (%rax),%eax
cmp    $0x20,%rax
ja     11b0 <parse_cmdline+0x30>
bt     %rax,%r13
jae    11b0 <parse_cmdline+0x30>
xor    %edi,%edi
call   1080 <add_cmd_char@plt>
mov    (%rsp),%rdi
call   1090 <skipsp@plt>
mov    %rax,(%rsp)
cmpb   $0x0,(%rax)
je     128f <parse_cmdline+0x10f>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <skipnsp@plt>
mov    %rax,(%rsp)
mov    (%rax),%bpl
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1030 <findaction@plt>
mov    %eax,%ebx
mov    (%rsp),%rax
mov    %bpl,(%rax)
mov    (%rsp),%rdi
call   1090 <skipsp@plt>
mov    %rax,(%rsp)
cmpb   $0x0,(%rax)
je     129d <parse_cmdline+0x11d>
or     $0x80,%bl
movsbl %bl,%edi
call   1080 <add_cmd_char@plt>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     128b <parse_cmdline+0x10b>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <tstr@plt>
mov    %rax,%rdi
call   1060 <add_cmd_str@plt>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    1270 <parse_cmdline+0xf0>
xor    %edi,%edi
jmp    12a0 <parse_cmdline+0x120>
lea    0xd7b(%rip),%rdi
call   1070 <lkerr@plt>
jmp    12a5 <parse_cmdline+0x125>
movsbl %bl,%edi
call   1080 <add_cmd_char@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"command too long\00"
@.str.1 = [15 x i8] c"missing action\00"
define void @parse_cmdline(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
br label %8
8: ; preds = %39, %1
%9 = call i8* @tstr(i8** %2, i32 1)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = call i64 @strlen(i8* %10)
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = add nsw i64 %13, %11
%15 = trunc i64 %14 to i32
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 16
br i1 %17, label %18, label %20
18: ; preds = %8
%19 = call i32 @lkerr(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %23
20: ; preds = %8
%21 = load i8*, i8** %6
%22 = call i32 @add_cmd_str(i8* %21)
br label %23
23: ; preds = %20, %18
br label %24
24: ; preds = %23
%25 = load i8*, i8** %2
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 32
br i1 %28, label %29, label %39
29: ; preds = %24
%30 = load i8*, i8** %2
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 9
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = load i8*, i8** %2
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 0
br label %39
39: ; preds = %34, %29, %24
%40 = phi i1 [ false, %29 ], [ false, %24 ], [ %38, %34 ]
br i1 %40, label %8, label %41
41: ; preds = %39
%42 = call i32 @add_cmd_char(i8 signext 0)
%43 = load i8*, i8** %2
%44 = call i8* @skipsp(i8* %43)
store i8* %44, i8** %2
%45 = load i8*, i8** %2
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %41
%50 = call i32 @lkerr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %87
51: ; preds = %41
%52 = load i8*, i8** %2
store i8* %52, i8** %4
%53 = load i8*, i8** %2
%54 = call i8* @skipnsp(i8* %53)
store i8* %54, i8** %2
%55 = load i8*, i8** %2
%56 = load i8, i8* %55
store i8 %56, i8* %7
%57 = load i8*, i8** %2
store i8 0, i8* %57
%58 = load i8*, i8** %4
%59 = call i32 @findaction(i8* %58)
store i32 %59, i32* %5
%60 = load i8, i8* %7
%61 = load i8*, i8** %2
store i8 %60, i8* %61
%62 = load i8*, i8** %2
%63 = call i8* @skipsp(i8* %62)
store i8* %63, i8** %2
%64 = load i8*, i8** %2
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %51
%69 = load i32, i32* %5
%70 = trunc i32 %69 to i8
%71 = call i32 @add_cmd_char(i8 signext %70)
br label %87
72: ; preds = %51
%73 = load i32, i32* %5
%74 = or i32 %73, 128
%75 = trunc i32 %74 to i8
%76 = call i32 @add_cmd_char(i8 signext %75)
br label %77
77: ; preds = %82, %72
%78 = load i8*, i8** %2
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %77
%83 = call i8* @tstr(i8** %2, i32 0)
%84 = call i32 @add_cmd_str(i8* %83)
br label %77
85: ; preds = %77
%86 = call i32 @add_cmd_char(i8 signext 0)
br label %87
87: ; preds = %49, %85, %68
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"command too long\00"
@.str.1 = [15 x i8] c"missing action\00"
define void @parse_cmdline(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
br label %3
3: ; preds = %16, %1
%4 = phi i64 [ 0, %1 ], [ %9, %16 ]
%5 = call i8* @tstr(i8** %2, i32 1)
%6 = call i64 @strlen(i8* dereferenceable(1) %5)
%7 = shl i64 %4, 32
%8 = ashr exact i64 %7, 32
%9 = add nsw i64 %8, %6
%10 = trunc i64 %9 to i32
%11 = icmp sgt i32 %10, 16
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @lkerr(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %16
14: ; preds = %3
%15 = call i32 @add_cmd_str(i8* %5)
br label %16
16: ; preds = %12, %14
%17 = load i8*, i8** %2
%18 = load i8, i8* %17
switch i8 %18, label %3 [
i8 32, label %19
i8 9, label %19
i8 0, label %19
]
19: ; preds = %16, %16, %16
%20 = call i32 @add_cmd_char(i8 signext 0)
%21 = load i8*, i8** %2
%22 = call i8* @skipsp(i8* %21)
store i8* %22, i8** %2
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @lkerr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %53
27: ; preds = %19
%28 = call i8* @skipnsp(i8* %22)
store i8* %28, i8** %2
%29 = load i8, i8* %28
store i8 0, i8* %28
%30 = call i32 @findaction(i8* %22)
%31 = load i8*, i8** %2
store i8 %29, i8* %31
%32 = load i8*, i8** %2
%33 = call i8* @skipsp(i8* %32)
store i8* %33, i8** %2
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
%36 = trunc i32 %30 to i8
br i1 %35, label %37, label %39
37: ; preds = %27
%38 = call i32 @add_cmd_char(i8 signext %36)
br label %53
39: ; preds = %27
%40 = or i8 %36, -128
%41 = call i32 @add_cmd_char(i8 signext %40)
%42 = load i8*, i8** %2
%43 = load i8, i8* %42
%44 = icmp eq i8 %43, 0
br i1 %44, label %51, label %45
45: ; preds = %39, %45
%46 = call i8* @tstr(i8** %2, i32 0)
%47 = call i32 @add_cmd_str(i8* %46)
%48 = load i8*, i8** %2
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, 0
br i1 %50, label %51, label %45
51: ; preds = %45, %39
%52 = call i32 @add_cmd_char(i8 signext 0)
br label %53
53: ; preds = %37, %51, %25
ret void
}