#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 */
typedef int /*<<< orphan*/ command;

/* Variables and functions */
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ get_token(char *, char **, char *, int);
int /*<<< orphan*/ strtrim(char *);
int /*<<< orphan*/ tokenize(char *, char *, int *, char ***);
int exec_internal_precommands(char *cmdline, char **cmdptr) {
  int tokc, retcode = 0;
  char **tokv;
  char *bufp;
  int direct_command(int, char **, int);
  char command[80];
  *cmdptr = bufp = cmdline;
  while (1) {
    get_token(command, &bufp, ";", sizeof(command) - 1);
    strtrim(command);
    if (*command != '@')
      break;
    tokenize(command, " \t\r\n", &tokc, &tokv);
    retcode = direct_command(tokc, tokv, 2);
    if (*bufp == ';')
      bufp++;
    *cmdptr = bufp;
    free(tokv);
    if (retcode != 0)
      break;
  }
  return retcode;
}


x86 assembly (clang, -O0):
<exec_internal_precommands>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rcx
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x80(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    0xe78(%rip),%rdx
mov    $0x4f,%ecx
call   1070 <get_token@plt>
lea    -0x80(%rbp),%rdi
call   1050 <strtrim@plt>
movsbl -0x80(%rbp),%eax
cmp    $0x40,%eax
je     11ad <exec_internal_precommands+0x5d>
jmp    121d <exec_internal_precommands+0xcd>
lea    -0x80(%rbp),%rdi
lea    0xe4a(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1040 <tokenize@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x2,%edx
call   1060 <direct_command@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
jne    11f5 <exec_internal_precommands+0xa5>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x18(%rbp)
je     1218 <exec_internal_precommands+0xc8>
jmp    121d <exec_internal_precommands+0xcd>
jmp    1179 <exec_internal_precommands+0x29>
mov    -0x18(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_internal_precommands>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%r15
mov    %rdi,0x8(%rsp)
mov    %rdi,(%rsi)
lea    0x20(%rsp),%rbx
lea    0x8(%rsp),%r12
lea    0x14(%rsp),%rbp
lea    0x18(%rsp),%r14
jmp    1192 <exec_internal_precommands+0x42>
nop
mov    %rax,(%r15)
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
test   %r13d,%r13d
jne    11fb <exec_internal_precommands+0xab>
mov    %rbx,%rdi
mov    %r12,%rsi
lea    0xe61(%rip),%rdx
mov    $0x4f,%ecx
call   1070 <get_token@plt>
mov    %rbx,%rdi
call   1050 <strtrim@plt>
cmpb   $0x40,0x20(%rsp)
jne    11f8 <exec_internal_precommands+0xa8>
mov    %rbx,%rdi
lea    0xe40(%rip),%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
call   1040 <tokenize@plt>
mov    0x14(%rsp),%edi
mov    0x18(%rsp),%rsi
mov    $0x2,%edx
call   1060 <direct_command@plt>
mov    %eax,%r13d
mov    0x8(%rsp),%rax
cmpb   $0x3b,(%rax)
jne    1180 <exec_internal_precommands+0x30>
add    $0x1,%rax
mov    %rax,0x8(%rsp)
jmp    1180 <exec_internal_precommands+0x30>
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c";\00"
@.str.1 = [5 x i8] c" \09\0D\0A\00"
define i32 @exec_internal_precommands(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca [80 x i8]
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 0, i32* %6
%10 = load i8*, i8** %3
store i8* %10, i8** %8
%11 = load i8**, i8*** %4
store i8* %10, i8** %11
br label %12
12: ; preds = %2, %43
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%14 = call i32 @get_token(i8* %13, i8** %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 79)
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%16 = call i32 @strtrim(i8* %15)
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 64
br i1 %20, label %21, label %22
21: ; preds = %12
br label %44
22: ; preds = %12
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%24 = call i32 @tokenize(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %5, i8*** %7)
%25 = load i32, i32* %5
%26 = load i8**, i8*** %7
%27 = call i32 @direct_command(i32 %25, i8** %26, i32 2)
store i32 %27, i32* %6
%28 = load i8*, i8** %8
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 59
br i1 %31, label %32, label %35
32: ; preds = %22
%33 = load i8*, i8** %8
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %8
br label %35
35: ; preds = %32, %22
%36 = load i8*, i8** %8
%37 = load i8**, i8*** %4
store i8* %36, i8** %37
%38 = load i8**, i8*** %7
%39 = call i32 @free(i8** %38)
%40 = load i32, i32* %6
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %35
br label %44
43: ; preds = %35
br label %12
44: ; preds = %42, %21
%45 = load i32, i32* %6
ret i32 %45
}

LLVM IR (-O2):
@.str = [2 x i8] c";\00"
@.str.1 = [5 x i8] c" \09\0D\0A\00"
define i32 @exec_internal_precommands(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca [80 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast i8*** %4 to i8*
%9 = bitcast i8** %5 to i8*
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
store i8* %0, i8** %5
store i8* %0, i8** %1
br label %11
11: ; preds = %26, %2
%12 = call i32 @get_token(i8* %10, i8** %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 79)
%13 = call i32 @strtrim(i8* %10)
%14 = load i8, i8* %10
%15 = icmp eq i8 %14, 64
br i1 %15, label %16, label %31
16: ; preds = %11
%17 = call i32 @tokenize(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %3, i8*** %4)
%18 = load i32, i32* %3
%19 = load i8**, i8*** %4
%20 = call i32 @direct_command(i32 %18, i8** %19, i32 2)
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 59
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %25, i8** %5
br label %26
26: ; preds = %24, %16
%27 = phi i8* [ %25, %24 ], [ %21, %16 ]
store i8* %27, i8** %1
%28 = load i8**, i8*** %4
%29 = call i32 @free(i8** %28)
%30 = icmp eq i32 %20, 0
br i1 %30, label %11, label %31
31: ; preds = %26, %11
%32 = phi i32 [ 0, %11 ], [ %20, %26 ]
ret i32 %32
}