#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 do_op(int, int, char);
int my_parse_nbr(char **);
int eval_expr_1(char **ps) {
  int lhs;
  int rhs;
  char op;
  lhs = my_parse_nbr(ps);
  while ((*ps)[0] == '*' || (*ps)[0] == '/' || (*ps)[0] == '%') {
    op = (*ps)[0];
    *ps = *ps + 1;
    rhs = my_parse_nbr(ps);
    lhs = do_op(lhs, rhs, op);
  }
  return (lhs);
}


x86 assembly (clang, -O0):
<eval_expr_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <my_parse_nbr@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x2a,%ecx
mov    %al,-0x12(%rbp)
je     117b <eval_expr_1+0x5b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x2f,%ecx
mov    %al,-0x12(%rbp)
je     117b <eval_expr_1+0x5b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
sete   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    118b <eval_expr_1+0x6b>
jmp    11cc <eval_expr_1+0xac>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <my_parse_nbr@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
movsbl -0x11(%rbp),%edx
call   1040 <do_op@plt>
mov    %eax,-0xc(%rbp)
jmp    1138 <eval_expr_1+0x18>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eval_expr_1>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <my_parse_nbr@plt>
mov    %eax,%r15d
movabs $0x842000000000,%r14
nopl   0x0(%rax)
mov    (%rbx),%rax
movzbl (%rax),%ebp
cmp    $0x2f,%rbp
ja     1174 <eval_expr_1+0x54>
bt     %rbp,%r14
jae    1174 <eval_expr_1+0x54>
add    $0x1,%rax
mov    %rax,(%rbx)
mov    %rbx,%rdi
call   1030 <my_parse_nbr@plt>
movsbl %bpl,%edx
mov    %r15d,%edi
mov    %eax,%esi
call   1040 <do_op@plt>
mov    %eax,%r15d
jmp    1140 <eval_expr_1+0x20>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @eval_expr_1(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i8** %0, i8*** %2
%6 = load i8**, i8*** %2
%7 = call i32 @my_parse_nbr(i8** %6)
store i32 %7, i32* %3
br label %8
8: ; preds = %31, %1
%9 = load i8**, i8*** %2
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 42
br i1 %14, label %29, label %15
15: ; preds = %8
%16 = load i8**, i8*** %2
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 47
br i1 %21, label %29, label %22
22: ; preds = %15
%23 = load i8**, i8*** %2
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 37
br label %29
29: ; preds = %22, %15, %8
%30 = phi i1 [ true, %15 ], [ true, %8 ], [ %28, %22 ]
br i1 %30, label %31, label %46
31: ; preds = %29
%32 = load i8**, i8*** %2
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
store i8 %35, i8* %5
%36 = load i8**, i8*** %2
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8**, i8*** %2
store i8* %38, i8** %39
%40 = load i8**, i8*** %2
%41 = call i32 @my_parse_nbr(i8** %40)
store i32 %41, i32* %4
%42 = load i32, i32* %3
%43 = load i32, i32* %4
%44 = load i8, i8* %5
%45 = call i32 @do_op(i32 %42, i32 %43, i8 signext %44)
store i32 %45, i32* %3
br label %8
46: ; preds = %29
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
define i32 @eval_expr_1(i8** %0) {
%2 = tail call i32 @my_parse_nbr(i8** %0)
br label %3
3: ; preds = %7, %1
%4 = phi i32 [ %2, %1 ], [ %10, %7 ]
%5 = load i8*, i8** %0
%6 = load i8, i8* %5
switch i8 %6, label %11 [
i8 42, label %7
i8 47, label %7
i8 37, label %7
]
7: ; preds = %3, %3, %3
%8 = getelementptr inbounds i8, i8* %5, i64 1
store i8* %8, i8** %0
%9 = tail call i32 @my_parse_nbr(i8** %0)
%10 = tail call i32 @do_op(i32 %4, i32 %9, i8 signext %6)
br label %3
11: ; preds = %3
ret i32 %4
}