#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 ui {
  int dummy;
};
struct ss_ts {
  int dummy;
};
struct forty_tag {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ handle_pops(struct ui *, void *, struct ss_ts *, int *);
int /*<<< orphan*/ handle_tag(struct ui *, void *, struct forty_tag const *,
                              struct ss_ts *, int *);
int /*<<< orphan*/ handle_text(struct ui *, void *,
                               void (*)(void *, struct ui *));
scalar_t__ ui_peek_c(struct ui *, char *);
void parse_stream(struct ui *is, struct ss_ts *ts, int *alt_ts,
                  const struct forty_tag *tl, void *context,
                  void print(void *, struct ui *)) {
  char tmp;
  while (ui_peek_c(is, &tmp)) {
    switch (tmp) {
    case '{':
      handle_tag(is, context, tl, ts, alt_ts);
      break;
    case '}':
      handle_pops(is, context, ts, alt_ts);
      break;
    default:
      handle_text(is, context, print);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<parse_stream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x31(%rbp),%rsi
call   1040 <ui_peek_c@plt>
cmp    $0x0,%rax
je     11eb <parse_stream+0xab>
movsbl -0x31(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x7b,%eax
je     119d <parse_stream+0x5d>
jmp    118c <parse_stream+0x4c>
mov    -0x38(%rbp),%eax
sub    $0x7d,%eax
je     11bb <parse_stream+0x7b>
jmp    11d5 <parse_stream+0x95>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1030 <handle_tag@plt>
jmp    11e6 <parse_stream+0xa6>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1050 <handle_pops@plt>
jmp    11e6 <parse_stream+0xa6>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1060 <handle_text@plt>
jmp    1160 <parse_stream+0x20>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_stream>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,%rbx
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbp
lea    0xf(%rsp),%rsi
call   1040 <ui_peek_c@plt>
test   %rax,%rax
je     11cd <parse_stream+0x8d>
lea    0xf(%rsp),%r14
jmp    119a <parse_stream+0x5a>
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rdx
call   1060 <handle_text@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <ui_peek_c@plt>
test   %rax,%rax
je     11cd <parse_stream+0x8d>
movsbl 0xf(%rsp),%eax
mov    %rbp,%rdi
mov    %rbx,%rsi
cmp    $0x7d,%eax
je     11c0 <parse_stream+0x80>
cmp    $0x7b,%eax
jne    1180 <parse_stream+0x40>
mov    %r15,%rdx
mov    %r13,%rcx
mov    %r12,%r8
call   1030 <handle_tag@plt>
jmp    118a <parse_stream+0x4a>
nop
mov    %r13,%rdx
mov    %r12,%rcx
call   1050 <handle_pops@plt>
jmp    118a <parse_stream+0x4a>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ui = type { i32 }
%struct.ss_ts = type { i32 }
%struct.forty_tag = type { i32 }
define void @parse_stream(%struct.ui* %0, %struct.ss_ts* %1, i32* %2, %struct.forty_tag* %3, i8* %4, void (i8*, %struct.ui*)* %5) {
%7 = alloca %struct.ui*
%8 = alloca %struct.ss_ts*
%9 = alloca i32*
%10 = alloca %struct.forty_tag*
%11 = alloca i8*
%12 = alloca void (i8*, %struct.ui*)*
%13 = alloca i8
store %struct.ui* %0, %struct.ui** %7
store %struct.ss_ts* %1, %struct.ss_ts** %8
store i32* %2, i32** %9
store %struct.forty_tag* %3, %struct.forty_tag** %10
store i8* %4, i8** %11
store void (i8*, %struct.ui*)* %5, void (i8*, %struct.ui*)** %12
br label %14
14: ; preds = %39, %6
%15 = load %struct.ui*, %struct.ui** %7
%16 = call i64 @ui_peek_c(%struct.ui* %15, i8* %13)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %40
18: ; preds = %14
%19 = load i8, i8* %13
%20 = sext i8 %19 to i32
switch i32 %20, label %34 [
i32 123, label %21
i32 125, label %28
]
21: ; preds = %18
%22 = load %struct.ui*, %struct.ui** %7
%23 = load i8*, i8** %11
%24 = load %struct.forty_tag*, %struct.forty_tag** %10
%25 = load %struct.ss_ts*, %struct.ss_ts** %8
%26 = load i32*, i32** %9
%27 = call i32 @handle_tag(%struct.ui* %22, i8* %23, %struct.forty_tag* %24, %struct.ss_ts* %25, i32* %26)
br label %39
28: ; preds = %18
%29 = load %struct.ui*, %struct.ui** %7
%30 = load i8*, i8** %11
%31 = load %struct.ss_ts*, %struct.ss_ts** %8
%32 = load i32*, i32** %9
%33 = call i32 @handle_pops(%struct.ui* %29, i8* %30, %struct.ss_ts* %31, i32* %32)
br label %39
34: ; preds = %18
%35 = load %struct.ui*, %struct.ui** %7
%36 = load i8*, i8** %11
%37 = load void (i8*, %struct.ui*)*, void (i8*, %struct.ui*)** %12
%38 = call i32 @handle_text(%struct.ui* %35, i8* %36, void (i8*, %struct.ui*)* %37)
br label %39
39: ; preds = %34, %28, %21
br label %14
40: ; preds = %14
ret void
}

LLVM IR (-O2):
%struct.ui = type { i32 }
%struct.ss_ts = type { i32 }
%struct.forty_tag = type { i32 }
define void @parse_stream(%struct.ui* %0, %struct.ss_ts* %1, i32* %2, %struct.forty_tag* %3, i8* %4, void (i8*, %struct.ui*)* %5) {
%7 = alloca i8
%8 = call i64 @ui_peek_c(%struct.ui* %0, i8* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %22, label %10
10: ; preds = %6, %19
%11 = load i8, i8* %7
%12 = sext i8 %11 to i32
switch i32 %12, label %17 [
i32 123, label %13
i32 125, label %15
]
13: ; preds = %10
%14 = call i32 @handle_tag(%struct.ui* %0, i8* %4, %struct.forty_tag* %3, %struct.ss_ts* %1, i32* %2)
br label %19
15: ; preds = %10
%16 = call i32 @handle_pops(%struct.ui* %0, i8* %4, %struct.ss_ts* %1, i32* %2)
br label %19
17: ; preds = %10
%18 = call i32 @handle_text(%struct.ui* %0, i8* %4, void (i8*, %struct.ui*)* %5)
br label %19
19: ; preds = %17, %15, %13
%20 = call i64 @ui_peek_c(%struct.ui* %0, i8* %7)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %10
22: ; preds = %19, %6
ret void
}