#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ nulterminate(struct cmd *);
int /*<<< orphan*/ panic(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);
    panic("syntax");
  }
  nulterminate(cmd);
  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   1050 <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   1060 <parseline@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x8(%rbp),%rdi
lea    0xe61(%rip),%rdx
call   1030 <peek@plt>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11e5 <parsecmd+0x85>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe2c(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xe2f(%rip),%rdi
call   1070 <panic@plt>
mov    -0x18(%rbp),%rdi
call   1040 <nulterminate@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   1050 <strlen@plt>
movslq %eax,%rbx
add    %r14,%rbx
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <parseline@plt>
mov    %rax,%r14
lea    0xe78(%rip),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <peek@plt>
mov    0x8(%rsp),%rdx
cmp    %rbx,%rdx
je     11cc <parsecmd+0x6c>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xe48(%rip),%rdi
call   1070 <panic@plt>
mov    %r14,%rdi
call   1040 <nulterminate@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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"
@.str.2 = [7 x i8] c"syntax\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 @panic(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %17, %1
%23 = load %struct.cmd*, %struct.cmd** %4
%24 = call i32 @nulterminate(%struct.cmd* %23)
%25 = load %struct.cmd*, %struct.cmd** %4
ret %struct.cmd* %25
}

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"
@.str.2 = [7 x i8] c"syntax\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 @panic(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %10, %1
%15 = call i32 @nulterminate(%struct.cmd* %6)
ret %struct.cmd* %6
}