#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*/ nulterminate(struct cmd *);
int /*<<< orphan*/ panic(char *);
struct cmd *parseline(char **, char *);
int /*<<< orphan*/ peek(char **, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
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) {
    printf("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   1070 <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     11dc <parsecmd+0x7c>
mov    -0x8(%rbp),%rsi
lea    0xe35(%rip),%rdi
call   1060 <printf@plt>
lea    0xe38(%rip),%rdi
call   1080 <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   1070 <parseline@plt>
mov    %rax,%r14
lea    0xe78(%rip),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <peek@plt>
mov    0x8(%rsp),%rsi
cmp    %rbx,%rsi
je     11c3 <parsecmd+0x63>
lea    0xe4e(%rip),%rdi
call   1060 <printf@plt>
lea    0xe51(%rip),%rdi
call   1080 <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
@.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 %21
17: ; preds = %1
%18 = load i8*, i8** %2
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 @panic(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %17, %1
%22 = load %struct.cmd*, %struct.cmd** %4
%23 = call i32 @nulterminate(%struct.cmd* %22)
%24 = load %struct.cmd*, %struct.cmd** %4
ret %struct.cmd* %24
}

LLVM IR (-O2):
%struct.cmd = type { i32 }
@.str = [1 x i8] zeroinitializer
@.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 %13, label %10
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%12 = call i32 @panic(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %10, %1
%14 = call i32 @nulterminate(%struct.cmd* %6)
ret %struct.cmd* %6
}