#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 cmd {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct cmd *parseline(char **, char *);
int /*<<< orphan*/ peek(char **, char *, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
struct cmd *parsecmd(char *s) {
  char *es;
  struct cmd *cmd;
  es = s + strlen(s);
  cmd = parseline(&s, es);
  peek(&s, es, "");
  if (s != es) {
    fprintf(stderr, "leftovers: %s\n", s);
    exit(-1);
  }
  return cmd;
}


x86 assembly (clang, -O0):
<parsecmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x8(%rbp),%rdi
call   1050 <parseline@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x8(%rbp),%rdi
lea    0xe71(%rip),%rdx
call   1030 <peek@plt>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11d3 <parsecmd+0x83>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe3c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsecmd>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    %rdi,0x8(%rsp)
call   1040 <strlen@plt>
movslq %eax,%rbx
add    %r14,%rbx
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <parseline@plt>
mov    %rax,%r14
lea    0xe88(%rip),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <peek@plt>
mov    0x8(%rsp),%rdx
cmp    %rbx,%rdx
jne    11a8 <parsecmd+0x58>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.cmd = type { i32 }
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [15 x i8] c"leftovers: %s\0A\00"
define %struct.cmd* @parsecmd(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.cmd*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %5, i64 %8
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = call %struct.cmd* @parseline(i8** %2, i8* %10)
store %struct.cmd* %11, %struct.cmd** %4
%12 = load i8*, i8** %3
%13 = call i32 @peek(i8** %2, i8* %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %2
%15 = load i8*, i8** %3
%16 = icmp ne i8* %14, %15
br i1 %16, label %17, label %22
17: ; preds = %1
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %2
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %1
%23 = load %struct.cmd*, %struct.cmd** %4
ret %struct.cmd* %23
}

LLVM IR (-O2):
%struct.cmd = type { i32 }
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [15 x i8] c"leftovers: %s\0A\00"
define %struct.cmd* @parsecmd(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = tail call i32 @strlen(i8* %0)
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = call %struct.cmd* @parseline(i8** %2, i8* %5)
%7 = call i32 @peek(i8** %2, i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %2
%9 = icmp eq i8* %8, %5
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %1
ret %struct.cmd* %6
}