#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 gges_bnf_production {
  int dummy;
};
struct gges_bnf_non_terminal {
  int dummy;
};
struct gges_bnf_grammar {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ append_token(struct gges_bnf_production *, char const *);
struct gges_bnf_non_terminal *create_non_terminal(struct gges_bnf_grammar *,
                                                  char const *);
struct gges_bnf_production *create_production(struct gges_bnf_non_terminal *);
struct gges_bnf_non_terminal *lookup_non_terminal(struct gges_bnf_grammar *,
                                                  char const *);
scalar_t__ strncmp(char *, char const *, int);
void process_token(struct gges_bnf_grammar *g,
                   struct gges_bnf_non_terminal **current_nt,
                   struct gges_bnf_production **current_p,
                   const char *current_token, const char *next_token) {
  if (next_token == NULL) {
    append_token(*current_p, current_token);
  } else if (strncmp("::=", next_token, 3) == 0) {
    *current_nt = lookup_non_terminal(g, current_token);
    if (*current_nt == NULL) {
      *current_nt = create_non_terminal(g, current_token);
    }
    *current_p = create_production(*current_nt);
  } else if (strncmp("|", next_token, 1) == 0) {
    append_token(*current_p, current_token);
    *current_p = create_production(*current_nt);
  } else {
    if (strncmp("::=", current_token, 3) == 0)
      return;
    if (strncmp("|", current_token, 1) == 0)
      return;
    append_token(*current_p, current_token);
  }
}


x86 assembly (clang, -O0):
<process_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118c <process_token+0x3c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <append_token@plt>
jmp    12ae <process_token+0x15e>
mov    -0x28(%rbp),%rsi
lea    0xe69(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1202 <process_token+0xb2>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <lookup_non_terminal@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11e7 <process_token+0x97>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <create_non_terminal@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <create_production@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    12a9 <process_token+0x159>
mov    -0x28(%rbp),%rsi
lea    0xdf7(%rip),%rdi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    124c <process_token+0xfc>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <append_token@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <create_production@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    12a4 <process_token+0x154>
mov    -0x20(%rbp),%rsi
lea    0xda9(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1270 <process_token+0x120>
jmp    12ae <process_token+0x15e>
mov    -0x20(%rbp),%rsi
lea    0xd89(%rip),%rdi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1294 <process_token+0x144>
jmp    12ae <process_token+0x15e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <append_token@plt>
jmp    12a9 <process_token+0x159>
jmp    12ae <process_token+0x15e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_token>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r12
mov    %rdx,%r14
test   %r8,%r8
je     11d1 <process_token+0x81>
mov    %r8,%rbx
mov    %rsi,%r15
mov    %rdi,%r13
lea    0xe8c(%rip),%rdi
mov    %r8,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11e5 <process_token+0x95>
lea    0xe77(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     120b <process_token+0xbb>
lea    0xe5a(%rip),%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1221 <process_token+0xd1>
lea    0xe45(%rip),%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1221 <process_token+0xd1>
mov    (%r14),%rdi
mov    %r12,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <append_token@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1070 <lookup_non_terminal@plt>
mov    %rax,(%r15)
test   %rax,%rax
jne    1206 <process_token+0xb6>
mov    %r13,%rdi
mov    %r12,%rsi
call   1060 <create_non_terminal@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
jmp    1219 <process_token+0xc9>
mov    (%r14),%rdi
mov    %r12,%rsi
call   1050 <append_token@plt>
mov    (%r15),%rdi
call   1040 <create_production@plt>
mov    %rax,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.gges_bnf_grammar = type { i32 }
%struct.gges_bnf_non_terminal = type { i32 }
%struct.gges_bnf_production = type { i32 }
@.str = [4 x i8] c"::=\00"
@.str.1 = [2 x i8] c"|\00"
define void @process_token(%struct.gges_bnf_grammar* %0, %struct.gges_bnf_non_terminal** %1, %struct.gges_bnf_production** %2, i8* %3, i8* %4) {
%6 = alloca %struct.gges_bnf_grammar*
%7 = alloca %struct.gges_bnf_non_terminal**
%8 = alloca %struct.gges_bnf_production**
%9 = alloca i8*
%10 = alloca i8*
store %struct.gges_bnf_grammar* %0, %struct.gges_bnf_grammar** %6
store %struct.gges_bnf_non_terminal** %1, %struct.gges_bnf_non_terminal*** %7
store %struct.gges_bnf_production** %2, %struct.gges_bnf_production*** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %5
%14 = load %struct.gges_bnf_production**, %struct.gges_bnf_production*** %8
%15 = load %struct.gges_bnf_production*, %struct.gges_bnf_production** %14
%16 = load i8*, i8** %9
%17 = call i32 @append_token(%struct.gges_bnf_production* %15, i8* %16)
br label %70
18: ; preds = %5
%19 = load i8*, i8** %10
%20 = call i64 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %19, i32 3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %40
22: ; preds = %18
%23 = load %struct.gges_bnf_grammar*, %struct.gges_bnf_grammar** %6
%24 = load i8*, i8** %9
%25 = call %struct.gges_bnf_non_terminal* @lookup_non_terminal(%struct.gges_bnf_grammar* %23, i8* %24)
%26 = load %struct.gges_bnf_non_terminal**, %struct.gges_bnf_non_terminal*** %7
store %struct.gges_bnf_non_terminal* %25, %struct.gges_bnf_non_terminal** %26
%27 = load %struct.gges_bnf_non_terminal**, %struct.gges_bnf_non_terminal*** %7
%28 = load %struct.gges_bnf_non_terminal*, %struct.gges_bnf_non_terminal** %27
%29 = icmp eq %struct.gges_bnf_non_terminal* %28, null
br i1 %29, label %30, label %35
30: ; preds = %22
%31 = load %struct.gges_bnf_grammar*, %struct.gges_bnf_grammar** %6
%32 = load i8*, i8** %9
%33 = call %struct.gges_bnf_non_terminal* @create_non_terminal(%struct.gges_bnf_grammar* %31, i8* %32)
%34 = load %struct.gges_bnf_non_terminal**, %struct.gges_bnf_non_terminal*** %7
store %struct.gges_bnf_non_terminal* %33, %struct.gges_bnf_non_terminal** %34
br label %35
35: ; preds = %30, %22
%36 = load %struct.gges_bnf_non_terminal**, %struct.gges_bnf_non_terminal*** %7
%37 = load %struct.gges_bnf_non_terminal*, %struct.gges_bnf_non_terminal** %36
%38 = call %struct.gges_bnf_production* @create_production(%struct.gges_bnf_non_terminal* %37)
%39 = load %struct.gges_bnf_production**, %struct.gges_bnf_production*** %8
store %struct.gges_bnf_production* %38, %struct.gges_bnf_production** %39
br label %69
40: ; preds = %18
%41 = load i8*, i8** %10
%42 = call i64 @strncmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %41, i32 1)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %53
44: ; preds = %40
%45 = load %struct.gges_bnf_production**, %struct.gges_bnf_production*** %8
%46 = load %struct.gges_bnf_production*, %struct.gges_bnf_production** %45
%47 = load i8*, i8** %9
%48 = call i32 @append_token(%struct.gges_bnf_production* %46, i8* %47)
%49 = load %struct.gges_bnf_non_terminal**, %struct.gges_bnf_non_terminal*** %7
%50 = load %struct.gges_bnf_non_terminal*, %struct.gges_bnf_non_terminal** %49
%51 = call %struct.gges_bnf_production* @create_production(%struct.gges_bnf_non_terminal* %50)
%52 = load %struct.gges_bnf_production**, %struct.gges_bnf_production*** %8
store %struct.gges_bnf_production* %51, %struct.gges_bnf_production** %52
br label %68
53: ; preds = %40
%54 = load i8*, i8** %9
%55 = call i64 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %54, i32 3)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %53
br label %70
58: ; preds = %53
%59 = load i8*, i8** %9
%60 = call i64 @strncmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %59, i32 1)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %58
br label %70
63: ; preds = %58
%64 = load %struct.gges_bnf_production**, %struct.gges_bnf_production*** %8
%65 = load %struct.gges_bnf_production*, %struct.gges_bnf_production** %64
%66 = load i8*, i8** %9
%67 = call i32 @append_token(%struct.gges_bnf_production* %65, i8* %66)
br label %68
68: ; preds = %63, %44
br label %69
69: ; preds = %68, %35
br label %70
70: ; preds = %57, %62, %69, %13
ret void
}

LLVM IR (-O2):
%struct.gges_bnf_grammar = type { i32 }
%struct.gges_bnf_non_terminal = type { i32 }
%struct.gges_bnf_production = type { i32 }
@.str = [4 x i8] c"::=\00"
@.str.1 = [2 x i8] c"|\00"
define void @process_token(%struct.gges_bnf_grammar* %0, %struct.gges_bnf_non_terminal** nocapture %1, %struct.gges_bnf_production** nocapture %2, i8* %3, i8* %4) {
%6 = icmp eq i8* %4, null
br i1 %6, label %7, label %10
7: ; preds = %5
%8 = load %struct.gges_bnf_production*, %struct.gges_bnf_production** %2
%9 = tail call i32 @append_token(%struct.gges_bnf_production* %8, i8* %3)
br label %38
10: ; preds = %5
%11 = tail call i64 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4, i32 3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = tail call %struct.gges_bnf_non_terminal* @lookup_non_terminal(%struct.gges_bnf_grammar* %0, i8* %3)
store %struct.gges_bnf_non_terminal* %14, %struct.gges_bnf_non_terminal** %1
%15 = icmp eq %struct.gges_bnf_non_terminal* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call %struct.gges_bnf_non_terminal* @create_non_terminal(%struct.gges_bnf_grammar* %0, i8* %3)
store %struct.gges_bnf_non_terminal* %17, %struct.gges_bnf_non_terminal** %1
br label %18
18: ; preds = %16, %13
%19 = phi %struct.gges_bnf_non_terminal* [ %17, %16 ], [ %14, %13 ]
%20 = tail call %struct.gges_bnf_production* @create_production(%struct.gges_bnf_non_terminal* %19)
store %struct.gges_bnf_production* %20, %struct.gges_bnf_production** %2
br label %38
21: ; preds = %10
%22 = tail call i64 @strncmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32 1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load %struct.gges_bnf_production*, %struct.gges_bnf_production** %2
%26 = tail call i32 @append_token(%struct.gges_bnf_production* %25, i8* %3)
%27 = load %struct.gges_bnf_non_terminal*, %struct.gges_bnf_non_terminal** %1
%28 = tail call %struct.gges_bnf_production* @create_production(%struct.gges_bnf_non_terminal* %27)
store %struct.gges_bnf_production* %28, %struct.gges_bnf_production** %2
br label %38
29: ; preds = %21
%30 = tail call i64 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %3, i32 3)
%31 = icmp eq i64 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %29
%33 = tail call i64 @strncmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 1)
%34 = icmp eq i64 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = load %struct.gges_bnf_production*, %struct.gges_bnf_production** %2
%37 = tail call i32 @append_token(%struct.gges_bnf_production* %36, i8* %3)
br label %38
38: ; preds = %18, %35, %24, %32, %29, %7
ret void
}