#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*/ line;

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
char *strtok(char *, char *);
void llvm_tokenize_stdin(void (*cb)(char **tokens, int ntokens)) {
  char line[1024];
  char *tokbuf[512];
  while (fgets(line, sizeof(line), stdin)) {
    int c = 0;
    if (line[0] == ';' || line[0] == '\n')
      continue;
    while (c < 512) {
      tokbuf[c] = strtok(c ? NULL : line, " \n");
      if (!tokbuf[c])
        break;
      c++;
    }
    if (c)
      cb(tokbuf, c);
  }
}


x86 assembly (clang, -O0):
<llvm_tokenize_stdin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1420,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
mov    0x2eab(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     1239 <llvm_tokenize_stdin+0x119>
movl   $0x0,-0x1414(%rbp)
movsbl -0x410(%rbp),%eax
cmp    $0x3b,%eax
je     117d <llvm_tokenize_stdin+0x5d>
movsbl -0x410(%rbp),%eax
cmp    $0xa,%eax
jne    1182 <llvm_tokenize_stdin+0x62>
jmp    112f <llvm_tokenize_stdin+0xf>
jmp    1187 <llvm_tokenize_stdin+0x67>
cmpl   $0x200,-0x1414(%rbp)
jge    1214 <llvm_tokenize_stdin+0xf4>
cmpl   $0x0,-0x1414(%rbp)
je     11b2 <llvm_tokenize_stdin+0x92>
xor    %eax,%eax
mov    %rax,-0x1420(%rbp)
jmp    11c0 <llvm_tokenize_stdin+0xa0>
lea    -0x410(%rbp),%rax
mov    %rax,-0x1420(%rbp)
mov    -0x1420(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,%rcx
movslq -0x1414(%rbp),%rax
mov    %rcx,-0x1410(%rbp,%rax,8)
ff
movslq -0x1414(%rbp),%rax
cmpq   $0x0,-0x1410(%rbp,%rax,8)
jne    1200 <llvm_tokenize_stdin+0xe0>
jmp    1214 <llvm_tokenize_stdin+0xf4>
mov    -0x1414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1414(%rbp)
jmp    1187 <llvm_tokenize_stdin+0x67>
cmpl   $0x0,-0x1414(%rbp)
je     1234 <llvm_tokenize_stdin+0x114>
mov    -0x8(%rbp),%rax
lea    -0x1410(%rbp),%rdi
mov    -0x1414(%rbp),%esi
call   *%rax
jmp    112f <llvm_tokenize_stdin+0xf>
add    $0x1420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<llvm_tokenize_stdin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1408,%rsp
mov    %rdi,%r14
mov    0x2ead(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %rsp,%r13
mov    %r13,%rdi
mov    $0x400,%esi
call   1030 <fgets@plt>
test   %rax,%rax
je     11d5 <llvm_tokenize_stdin+0xb5>
lea    0xea2(%rip),%r15
lea    0x400(%rsp),%r12
jmp    1189 <llvm_tokenize_stdin+0x69>
test   %ebx,%ebx
je     1174 <llvm_tokenize_stdin+0x54>
mov    %r12,%rdi
mov    %ebx,%esi
call   *%r14
mov    0x0(%rbp),%edx
mov    %r13,%rdi
mov    $0x400,%esi
call   1030 <fgets@plt>
test   %rax,%rax
je     11d5 <llvm_tokenize_stdin+0xb5>
mov    (%rsp),%al
cmp    $0xa,%al
je     1174 <llvm_tokenize_stdin+0x54>
cmp    $0x3b,%al
je     1174 <llvm_tokenize_stdin+0x54>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
test   %rbx,%rbx
mov    $0x0,%edi
cmove  %r13,%rdi
mov    %r15,%rsi
call   1040 <strtok@plt>
mov    %rax,0x400(%rsp,%rbx,8)
test   %rax,%rax
je     1168 <llvm_tokenize_stdin+0x48>
add    $0x1,%rbx
cmp    $0x200,%rbx
jne    11a0 <llvm_tokenize_stdin+0x80>
mov    $0x200,%ebx
jmp    116c <llvm_tokenize_stdin+0x4c>
add    $0x1408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c" \0A\00"
define void @llvm_tokenize_stdin(void (i8**, i32)* %0) {
%2 = alloca void (i8**, i32)*
%3 = alloca [1024 x i8]
%4 = alloca [512 x i8*]
%5 = alloca i32
store void (i8**, i32)* %0, void (i8**, i32)** %2
br label %6
6: ; preds = %54, %21, %1
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i64 @fgets(i8* %7, i32 1024, i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %55
11: ; preds = %6
store i32 0, i32* %5
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 59
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %22
21: ; preds = %16, %11
br label %6
22: ; preds = %16
br label %23
23: ; preds = %44, %22
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 512
br i1 %25, label %26, label %47
26: ; preds = %23
%27 = load i32, i32* %5
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
br label %32
30: ; preds = %26
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %32
32: ; preds = %30, %29
%33 = phi i8* [ null, %29 ], [ %31, %30 ]
%34 = call i8* @strtok(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [512 x i8*], [512 x i8*]* %4, i64 0, i64 %36
store i8* %34, i8** %37
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [512 x i8*], [512 x i8*]* %4, i64 0, i64 %39
%41 = load i8*, i8** %40
%42 = icmp ne i8* %41, null
br i1 %42, label %44, label %43
43: ; preds = %32
br label %47
44: ; preds = %32
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
br label %23
47: ; preds = %43, %23
%48 = load i32, i32* %5
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = load void (i8**, i32)*, void (i8**, i32)** %2
%52 = getelementptr inbounds [512 x i8*], [512 x i8*]* %4, i64 0, i64 0
%53 = load i32, i32* %5
br label %54
54: ; preds = %50, %47
br label %6
55: ; preds = %6
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c" \0A\00"
define void @llvm_tokenize_stdin(void (i8**, i32)* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = alloca [512 x i8*]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = bitcast [512 x i8*]* %3 to i8*
%6 = load i32, i32* @stdin
%7 = call i64 @fgets(i8* %4, i32 1024, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %32, label %9
9: ; preds = %1
%10 = getelementptr inbounds [512 x i8*], [512 x i8*]* %3, i64 0, i64 0
br label %11
11: ; preds = %9, %28
%12 = load i8, i8* %4
switch i8 %12, label %13 [
i8 59, label %28
i8 10, label %28
]
13: ; preds = %11, %20
%14 = phi i64 [ %21, %20 ], [ 0, %11 ]
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i8* %4, i8* null
%17 = call i8* @strtok(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = getelementptr inbounds [512 x i8*], [512 x i8*]* %3, i64 0, i64 %14
store i8* %17, i8** %18
%19 = icmp eq i8* %17, null
br i1 %19, label %23, label %20
20: ; preds = %13
%21 = add nuw nsw i64 %14, 1
%22 = icmp eq i64 %21, 512
br i1 %22, label %26, label %13
23: ; preds = %13
%24 = trunc i64 %14 to i32
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %20, %23
%27 = phi i32 [ %24, %23 ], [ 512, %20 ]
br label %28
28: ; preds = %23, %26, %11, %11
%29 = load i32, i32* @stdin
%30 = call i64 @fgets(i8* %4, i32 1024, i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %11
32: ; preds = %28, %1
ret void
}