#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 */
char *getexpr(char *, unsigned int *);
char *getval(char *, unsigned int *);
size_t nextchar(char *, int /*<<< orphan*/);
char *getterm(char *a, unsigned int *par) {
  if (*a == '<') {
    a = getterm(&a[1], par);
    if (*par > 0xffff)
      return NULL;
    *par = *par & 255;
    return a;
  }
  if (*a == '>') {
    a = getterm(&a[1], par);
    if (*par > 0xffff)
      return NULL;
    *par = (*par >> 8) & 255;
    return a;
  }
  if (*a == '(') {
    a = getexpr(&a[1], par);
    if (a == NULL)
      return NULL;
    a = &a[nextchar(a, 0)];
    if (*a != ')')
      return NULL;
    return &a[1];
  } else
    return getval(a, par);
}


x86 assembly (clang, -O0):
<getterm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3c,%eax
jne    11b1 <getterm+0x71>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1040 <getterm@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0xffff,(%rax)
jbe    1192 <getterm+0x52>
movq   $0x0,-0x8(%rbp)
jmp    12b2 <getterm+0x172>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12b2 <getterm+0x172>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3e,%eax
jne    1215 <getterm+0xd5>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1040 <getterm@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0xffff,(%rax)
jbe    11f3 <getterm+0xb3>
movq   $0x0,-0x8(%rbp)
jmp    12b2 <getterm+0x172>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
shr    $0x8,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12b2 <getterm+0x172>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
jne    12a1 <getterm+0x161>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1060 <getexpr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1252 <getterm+0x112>
movq   $0x0,-0x8(%rbp)
jmp    12b2 <getterm+0x172>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1050 <nextchar@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
je     1290 <getterm+0x150>
movq   $0x0,-0x8(%rbp)
jmp    12b2 <getterm+0x172>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    12b2 <getterm+0x172>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <getval@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getterm>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    (%rdi),%al
cmp    $0x28,%al
je     1172 <getterm+0x32>
cmp    $0x3e,%al
je     11a2 <getterm+0x62>
cmp    $0x3c,%al
jne    11bf <getterm+0x7f>
add    $0x1,%rdi
mov    %rbx,%rsi
call   1040 <getterm@plt>
mov    %rax,%r14
mov    (%rbx),%eax
cmp    $0xffff,%eax
ja     11ba <getterm+0x7a>
movzbl %al,%eax
jmp    11d1 <getterm+0x91>
add    $0x1,%rdi
mov    %rbx,%rsi
call   1060 <getexpr@plt>
test   %rax,%rax
je     11ba <getterm+0x7a>
mov    %rax,%rbx
xor    %r14d,%r14d
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <nextchar@plt>
cmpb   $0x29,(%rbx,%rax,1)
lea    0x1(%rbx,%rax,1),%rax
cmove  %rax,%r14
jmp    11d3 <getterm+0x93>
add    $0x1,%rdi
mov    %rbx,%rsi
call   1040 <getterm@plt>
mov    %rax,%r14
mov    (%rbx),%eax
cmp    $0xffff,%eax
jbe    11ce <getterm+0x8e>
xor    %r14d,%r14d
jmp    11d3 <getterm+0x93>
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <getval@plt>
shr    $0x8,%eax
mov    %eax,(%rbx)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @getterm(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
%6 = load i8*, i8** %4
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 60
br i1 %9, label %10, label %25
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i32*, i32** %5
%14 = call i8* @getterm(i8* %12, i32* %13)
store i8* %14, i8** %4
%15 = load i32*, i32** %5
%16 = load i32, i32* %15
%17 = icmp ugt i32 %16, 65535
br i1 %17, label %18, label %19
18: ; preds = %10
store i8* null, i8** %3
br label %76
19: ; preds = %10
%20 = load i32*, i32** %5
%21 = load i32, i32* %20
%22 = and i32 %21, 255
%23 = load i32*, i32** %5
store i32 %22, i32* %23
%24 = load i8*, i8** %4
store i8* %24, i8** %3
br label %76
25: ; preds = %2
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 62
br i1 %29, label %30, label %46
30: ; preds = %25
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i32*, i32** %5
%34 = call i8* @getterm(i8* %32, i32* %33)
store i8* %34, i8** %4
%35 = load i32*, i32** %5
%36 = load i32, i32* %35
%37 = icmp ugt i32 %36, 65535
br i1 %37, label %38, label %39
38: ; preds = %30
store i8* null, i8** %3
br label %76
39: ; preds = %30
%40 = load i32*, i32** %5
%41 = load i32, i32* %40
%42 = lshr i32 %41, 8
%43 = and i32 %42, 255
%44 = load i32*, i32** %5
store i32 %43, i32* %44
%45 = load i8*, i8** %4
store i8* %45, i8** %3
br label %76
46: ; preds = %25
%47 = load i8*, i8** %4
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 40
br i1 %50, label %51, label %72
51: ; preds = %46
%52 = load i8*, i8** %4
%53 = getelementptr inbounds i8, i8* %52, i64 1
%54 = load i32*, i32** %5
%55 = call i8* @getexpr(i8* %53, i32* %54)
store i8* %55, i8** %4
%56 = load i8*, i8** %4
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %59
58: ; preds = %51
store i8* null, i8** %3
br label %76
59: ; preds = %51
%60 = load i8*, i8** %4
%61 = load i8*, i8** %4
%62 = call i64 @nextchar(i8* %61, i32 0)
%63 = getelementptr inbounds i8, i8* %60, i64 %62
store i8* %63, i8** %4
%64 = load i8*, i8** %4
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp ne i32 %66, 41
br i1 %67, label %68, label %69
68: ; preds = %59
store i8* null, i8** %3
br label %76
69: ; preds = %59
%70 = load i8*, i8** %4
%71 = getelementptr inbounds i8, i8* %70, i64 1
store i8* %71, i8** %3
br label %76
72: ; preds = %46
%73 = load i8*, i8** %4
%74 = load i32*, i32** %5
%75 = call i8* @getval(i8* %73, i32* %74)
store i8* %75, i8** %3
br label %76
76: ; preds = %72, %69, %68, %58, %39, %38, %19, %18
%77 = load i8*, i8** %3
ret i8* %77
}

LLVM IR (-O2):
define i8* @getterm(i8* %0, i32* %1) {
%3 = load i8, i8* %0
switch i8 %3, label %29 [
i8 60, label %4
i8 62, label %11
i8 40, label %18
]
4: ; preds = %2
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = tail call i8* @getterm(i8* %5, i32* %1)
%7 = load i32, i32* %1
%8 = icmp ugt i32 %7, 65535
br i1 %8, label %31, label %9
9: ; preds = %4
%10 = and i32 %7, 255
store i32 %10, i32* %1
br label %31
11: ; preds = %2
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = tail call i8* @getterm(i8* %12, i32* %1)
%14 = load i32, i32* %1
%15 = icmp ugt i32 %14, 65535
br i1 %15, label %31, label %16
16: ; preds = %11
%17 = lshr i32 %14, 8
store i32 %17, i32* %1
br label %31
18: ; preds = %2
%19 = getelementptr inbounds i8, i8* %0, i64 1
%20 = tail call i8* @getexpr(i8* %19, i32* %1)
%21 = icmp eq i8* %20, null
br i1 %21, label %31, label %22
22: ; preds = %18
%23 = tail call i64 @nextchar(i8* %20, i32 0)
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 41
%27 = getelementptr inbounds i8, i8* %24, i64 1
%28 = select i1 %26, i8* %27, i8* null
br label %31
29: ; preds = %2
%30 = tail call i8* @getval(i8* %0, i32* %1)
br label %31
31: ; preds = %22, %18, %11, %4, %29, %16, %9
%32 = phi i8* [ %6, %9 ], [ %13, %16 ], [ %30, %29 ], [ null, %4 ], [ null, %11 ], [ null, %18 ], [ %28, %22 ]
ret i8* %32
}