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

/* Variables and functions */
int factor(char *, int);
int lexer(char);
int /*<<< orphan*/ printf(char *, char);
int parser(char string[]) {
  int ctr = 0;
  char letter;
  int token = 0;
  int token1 = 0;
  int checked = 0;
  do {
    letter = string[ctr];
    ctr++;
  } while (letter == ' ');
  token = lexer(letter);
  do {
    letter = string[ctr];
    ctr++;
  } while (letter == ' ');
  token1 = lexer(letter);
  if (token == 1) {
    if (token1 == 2) {
      checked = factor(string, ctr);
    } else {
      printf("error at char %c", letter);
    }
  }
  return checked;
}


x86 assembly (clang, -O0):
<parser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xd(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0x20,%eax
je     1158 <parser+0x28>
movsbl -0xd(%rbp),%edi
call   1050 <lexer@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xd(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0x20,%eax
je     1188 <parser+0x58>
movsbl -0xd(%rbp),%edi
call   1050 <lexer@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    11f5 <parser+0xc5>
cmpl   $0x2,-0x18(%rbp)
jne    11e0 <parser+0xb0>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <factor@plt>
mov    %eax,-0x1c(%rbp)
jmp    11f0 <parser+0xc0>
lea    0xe19(%rip),%rdi
movsbl -0xd(%rbp),%esi
call   1030 <printf@plt>
jmp    11f5 <parser+0xc5>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parser>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
xor    %ebx,%ebx
nopl   (%rax)
movzbl (%r14,%rbx,1),%eax
add    $0x1,%rbx
cmp    $0x20,%al
je     1140 <parser+0x10>
movsbl %al,%edi
call   1050 <lexer@plt>
mov    %eax,%r15d
mov    %ebx,%eax
add    %r14,%rax
xor    %ebp,%ebp
nop
movzbl (%rax,%rbp,1),%ecx
add    $0x1,%rbp
cmp    $0x20,%cl
je     1160 <parser+0x30>
movsbl %cl,%r12d
mov    %r12d,%edi
call   1050 <lexer@plt>
cmp    $0x1,%r15d
jne    11a7 <parser+0x77>
cmp    $0x2,%eax
jne    1198 <parser+0x68>
add    %ebp,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <factor@plt>
lea    0xe61(%rip),%rdi
mov    %r12d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"error at char %c\00"
define i32 @parser(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %16, %1
%9 = load i8*, i8** %2
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
store i8 %13, i8* %4
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
br label %16
16: ; preds = %8
%17 = load i8, i8* %4
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 32
br i1 %19, label %8, label %20
20: ; preds = %16
%21 = load i8, i8* %4
%22 = call i32 @lexer(i8 signext %21)
store i32 %22, i32* %5
br label %23
23: ; preds = %31, %20
%24 = load i8*, i8** %2
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
store i8 %28, i8* %4
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %31
31: ; preds = %23
%32 = load i8, i8* %4
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 32
br i1 %34, label %23, label %35
35: ; preds = %31
%36 = load i8, i8* %4
%37 = call i32 @lexer(i8 signext %36)
store i32 %37, i32* %6
%38 = load i32, i32* %5
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %51
40: ; preds = %35
%41 = load i32, i32* %6
%42 = icmp eq i32 %41, 2
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i8*, i8** %2
%45 = load i32, i32* %3
%46 = call i32 @factor(i8* %44, i32 %45)
store i32 %46, i32* %7
br label %50
47: ; preds = %40
%48 = load i8, i8* %4
%49 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %48)
br label %50
50: ; preds = %47, %43
br label %51
51: ; preds = %50, %35
%52 = load i32, i32* %7
ret i32 %52
}

LLVM IR (-O2):
@.str = [17 x i8] c"error at char %c\00"
define i32 @parser(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ %6, %2 ], [ 0, %1 ]
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = add nuw i64 %3, 1
%7 = icmp eq i8 %5, 32
br i1 %7, label %2, label %8
8: ; preds = %2
%9 = tail call i32 @lexer(i8 signext %5)
%10 = and i64 %6, 4294967295
br label %11
11: ; preds = %11, %8
%12 = phi i64 [ %15, %11 ], [ %10, %8 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = add nuw i64 %12, 1
%16 = icmp eq i8 %14, 32
br i1 %16, label %11, label %17
17: ; preds = %11
%18 = trunc i64 %15 to i32
%19 = tail call i32 @lexer(i8 signext %14)
%20 = icmp eq i32 %9, 1
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = icmp eq i32 %19, 2
br i1 %22, label %23, label %25
23: ; preds = %21
%24 = tail call i32 @factor(i8* %0, i32 %18)
br label %27
25: ; preds = %21
%26 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %14)
br label %27
27: ; preds = %23, %25, %17
%28 = phi i32 [ %24, %23 ], [ 0, %25 ], [ 0, %17 ]
ret i32 %28
}