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(2, "leftovers: %s\n", s);
    die("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    %rax,%rcx
mov    -0x20(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1070 <parseline@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x8(%rbp),%rdi
lea    0xe5f(%rip),%rdx
mov    $0x0,%al
call   1030 <peek@plt>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11e9 <parsecmd+0x89>
mov    -0x8(%rbp),%rdx
mov    $0x2,%edi
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1080 <die@plt>
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
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>
mov    %rax,%rbx
add    %r14,%rbx
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <parseline@plt>
movslq %eax,%r14
lea    0xe76(%rip),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <peek@plt>
mov    0x8(%rsp),%rdx
cmp    %rbx,%rdx
je     11d0 <parsecmd+0x70>
lea    0xe4a(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe46(%rip),%rdi
xor    %eax,%eax
call   1080 <die@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <nulterminate@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.cmd = type opaque
@.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 i64 @strlen(i8* %6)
%8 = getelementptr inbounds i8, i8* %5, i64 %7
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 (i8**, i8*, ...) bitcast (i32 (...)* @parseline to i32 (i8**, i8*, ...)*)(i8** %2, i8* %9)
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to %struct.cmd*
store %struct.cmd* %12, %struct.cmd** %4
%13 = load i8*, i8** %3
%14 = call i32 (i8**, i8*, i8*, ...) bitcast (i32 (...)* @peek to i32 (i8**, i8*, i8*, ...)*)(i8** %2, i8* %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%15 = load i8*, i8** %2
%16 = load i8*, i8** %3
%17 = icmp ne i8* %15, %16
br i1 %17, label %18, label %22
18: ; preds = %1
%19 = load i8*, i8** %2
%20 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 2 to i8*), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = call i32 (i8*, ...) bitcast (i32 (...)* @die to i32 (i8*, ...)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %18, %1
%23 = load %struct.cmd*, %struct.cmd** %4
%24 = call i32 (%struct.cmd*, ...) bitcast (i32 (...)* @nulterminate to i32 (%struct.cmd*, ...)*)(%struct.cmd* %23)
%25 = load %struct.cmd*, %struct.cmd** %4
ret %struct.cmd* %25
}

LLVM IR (-O2):
%struct.cmd = type opaque
@.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 i64 @strlen(i8* dereferenceable(1) %0)
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = call i32 (i8**, i8*, ...) bitcast (i32 (...)* @parseline to i32 (i8**, i8*, ...)*)(i8** %2, i8* %4)
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to %struct.cmd*
%8 = call i32 (i8**, i8*, i8*, ...) bitcast (i32 (...)* @peek to i32 (i8**, i8*, i8*, ...)*)(i8** %2, i8* %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %2
%10 = icmp eq i8* %9, %4
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 2 to i8*), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%13 = call i32 (i8*, ...) bitcast (i32 (...)* @die to i32 (i8*, ...)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %11, %1
%15 = call i32 (%struct.cmd*, ...) bitcast (i32 (...)* @nulterminate to i32 (%struct.cmd*, ...)*)(%struct.cmd* %7)
ret %struct.cmd* %7
}