#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 mb_interpreter_t {
  int dummy;
};
typedef int /*<<< orphan*/ frames;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int mb_attempt_close_bracket(struct mb_interpreter_t *, void **);
int mb_attempt_open_bracket(struct mb_interpreter_t *, void **);
int mb_debug_get_stack_trace(struct mb_interpreter_t *, void **, char **, int);
int /*<<< orphan*/ memset(char **, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int trace(struct mb_interpreter_t *s, void **l) {
  int result = 0;
  char *frames[16];
  int i = 0;
  do {
    ((void)(s && l));
    assert(s && l);
  } while (0);
  memset(frames, 0, sizeof(frames));
  do {
    int __hr = (mb_attempt_open_bracket(s, l));
    if ((__hr) != 0) {
      return (__hr);
    }
  } while (0);
  do {
    int __hr = (mb_attempt_close_bracket(s, l));
    if ((__hr) != 0) {
      return (__hr);
    }
  } while (0);
  do {
    int __hr = (mb_debug_get_stack_trace(s, l, frames,
                                         (sizeof(frames) / sizeof(*(frames)))));
    if ((__hr) != 0) {
      return (__hr);
    }
  } while (0);
  for (i = 1; i < (sizeof(frames) / sizeof(*(frames)));) {
    if (frames[i]) {
      printf("%s", frames[i]);
    }
    if (++i < (sizeof(frames) / sizeof(*(frames))) && frames[i]) {
      printf(" <- ");
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<trace>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0xa4(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0xb1(%rbp)
je     11a5 <trace+0x45>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0xb1(%rbp)
mov    -0xb1(%rbp),%al
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0xb2(%rbp)
je     11cc <trace+0x6c>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0xb2(%rbp)
mov    -0xb2(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <mb_attempt_open_bracket@plt>
mov    %eax,-0xa8(%rbp)
cmpl   $0x0,-0xa8(%rbp)
je     121d <trace+0xbd>
mov    -0xa8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1336 <trace+0x1d6>
jmp    1222 <trace+0xc2>
jmp    1227 <trace+0xc7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <mb_attempt_close_bracket@plt>
mov    %eax,-0xac(%rbp)
cmpl   $0x0,-0xac(%rbp)
je     1255 <trace+0xf5>
mov    -0xac(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1336 <trace+0x1d6>
jmp    125a <trace+0xfa>
jmp    125f <trace+0xff>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0xa0(%rbp),%rdx
mov    $0x10,%ecx
call   1050 <mb_debug_get_stack_trace@plt>
mov    %eax,-0xb0(%rbp)
cmpl   $0x0,-0xb0(%rbp)
je     1299 <trace+0x139>
mov    -0xb0(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1336 <trace+0x1d6>
jmp    129e <trace+0x13e>
movl   $0x1,-0xa4(%rbp)
movslq -0xa4(%rbp),%rax
cmp    $0x10,%rax
jae    1330 <trace+0x1d0>
movslq -0xa4(%rbp),%rax
cmpq   $0x0,-0xa0(%rbp,%rax,8)
je     12ec <trace+0x18c>
movslq -0xa4(%rbp),%rax
mov    -0xa0(%rbp,%rax,8),%rsi
ff
lea    0xd1b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
cltq
cmp    $0x10,%rax
jae    132b <trace+0x1cb>
movslq -0xa4(%rbp),%rax
cmpq   $0x0,-0xa0(%rbp,%rax,8)
je     132b <trace+0x1cb>
lea    0xcdf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a8 <trace+0x148>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trace>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1060 <assert@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <mb_attempt_open_bracket@plt>
test   %eax,%eax
jne    122d <trace+0xcd>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <mb_attempt_close_bracket@plt>
test   %eax,%eax
jne    122d <trace+0xcd>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x10,%ecx
call   1050 <mb_debug_get_stack_trace@plt>
test   %eax,%eax
jne    122d <trace+0xcd>
lea    0xe2a(%rip),%r14
lea    0xe20(%rip),%r15
xor    %r12d,%r12d
jmp    11f6 <trace+0x96>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0xf,%r12
je     122b <trace+0xcb>
mov    %r12,%rbx
add    $0x1,%r12
mov    0x8(%rsp,%rbx,8),%rsi
test   %rsi,%rsi
je     1211 <trace+0xb1>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0xe,%r12
ja     11f0 <trace+0x90>
cmpq   $0x0,0x10(%rsp,%rbx,8)
je     11f0 <trace+0x90>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11f0 <trace+0x90>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.mb_interpreter_t = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [5 x i8] c" <- \00"
define i32 @trace(%struct.mb_interpreter_t* %0, i8** %1) {
%3 = alloca i32
%4 = alloca %struct.mb_interpreter_t*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [16 x i8*]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store %struct.mb_interpreter_t* %0, %struct.mb_interpreter_t** %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %8
br label %12
12: ; preds = %2
%13 = load %struct.mb_interpreter_t*, %struct.mb_interpreter_t** %4
%14 = icmp ne %struct.mb_interpreter_t* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i8**, i8*** %5
%17 = icmp ne i8** %16, null
br label %18
18: ; preds = %15, %12
%19 = phi i1 [ false, %12 ], [ %17, %15 ]
%20 = zext i1 %19 to i32
%21 = load %struct.mb_interpreter_t*, %struct.mb_interpreter_t** %4
%22 = icmp ne %struct.mb_interpreter_t* %21, null
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i8**, i8*** %5
%25 = icmp ne i8** %24, null
br label %26
26: ; preds = %23, %18
%27 = phi i1 [ false, %18 ], [ %25, %23 ]
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
br label %30
30: ; preds = %26
%31 = getelementptr inbounds [16 x i8*], [16 x i8*]* %7, i64 0, i64 0
%32 = call i32 @memset(i8** %31, i32 0, i32 128)
br label %33
33: ; preds = %30
%34 = load %struct.mb_interpreter_t*, %struct.mb_interpreter_t** %4
%35 = load i8**, i8*** %5
%36 = call i32 @mb_attempt_open_bracket(%struct.mb_interpreter_t* %34, i8** %35)
store i32 %36, i32* %9
%37 = load i32, i32* %9
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = load i32, i32* %9
store i32 %40, i32* %3
br label %96
41: ; preds = %33
br label %42
42: ; preds = %41
br label %43
43: ; preds = %42
%44 = load %struct.mb_interpreter_t*, %struct.mb_interpreter_t** %4
%45 = load i8**, i8*** %5
%46 = call i32 @mb_attempt_close_bracket(%struct.mb_interpreter_t* %44, i8** %45)
store i32 %46, i32* %10
%47 = load i32, i32* %10
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %43
%50 = load i32, i32* %10
store i32 %50, i32* %3
br label %96
51: ; preds = %43
br label %52
52: ; preds = %51
br label %53
53: ; preds = %52
%54 = load %struct.mb_interpreter_t*, %struct.mb_interpreter_t** %4
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds [16 x i8*], [16 x i8*]* %7, i64 0, i64 0
%57 = call i32 @mb_debug_get_stack_trace(%struct.mb_interpreter_t* %54, i8** %55, i8** %56, i32 16)
store i32 %57, i32* %11
%58 = load i32, i32* %11
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %53
%61 = load i32, i32* %11
store i32 %61, i32* %3
br label %96
62: ; preds = %53
br label %63
63: ; preds = %62
store i32 1, i32* %8
br label %64
64: ; preds = %93, %63
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = icmp ult i64 %66, 16
br i1 %67, label %68, label %94
68: ; preds = %64
%69 = load i32, i32* %8
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [16 x i8*], [16 x i8*]* %7, i64 0, i64 %70
%72 = load i8*, i8** %71
%73 = icmp ne i8* %72, null
br i1 %73, label %74, label %80
74: ; preds = %68
%75 = load i32, i32* %8
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [16 x i8*], [16 x i8*]* %7, i64 0, i64 %76
%78 = load i8*, i8** %77
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %78)
br label %80
80: ; preds = %74, %68
%81 = load i32, i32* %8
%82 = add nsw i32 %81, 1
store i32 %82, i32* %8
%83 = sext i32 %82 to i64
%84 = icmp ult i64 %83, 16
br i1 %84, label %85, label %93
85: ; preds = %80
%86 = load i32, i32* %8
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [16 x i8*], [16 x i8*]* %7, i64 0, i64 %87
%89 = load i8*, i8** %88
%90 = icmp ne i8* %89, null
br i1 %90, label %91, label %93
91: ; preds = %85
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %93
93: ; preds = %91, %85, %80
br label %64
94: ; preds = %64
%95 = load i32, i32* %6
store i32 %95, i32* %3
br label %96
96: ; preds = %94, %60, %49, %39
%97 = load i32, i32* %3
ret i32 %97
}

LLVM IR (-O2):
%struct.mb_interpreter_t = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [5 x i8] c" <- \00"
define i32 @trace(%struct.mb_interpreter_t* %0, i8** %1) {
%3 = alloca [16 x i8*]
%4 = bitcast [16 x i8*]* %3 to i8*
%5 = icmp ne %struct.mb_interpreter_t* %0, null
%6 = icmp ne i8** %1, null
%7 = and i1 %5, %6
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 0
%11 = call i32 @memset(i8** %10, i32 0, i32 128)
%12 = call i32 @mb_attempt_open_bracket(%struct.mb_interpreter_t* %0, i8** %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %38
14: ; preds = %2
%15 = call i32 @mb_attempt_close_bracket(%struct.mb_interpreter_t* %0, i8** %1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %38
17: ; preds = %14
%18 = call i32 @mb_debug_get_stack_trace(%struct.mb_interpreter_t* %0, i8** %1, i8** %10, i32 16)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %38
20: ; preds = %17, %36
%21 = phi i64 [ %28, %36 ], [ 1, %17 ]
%22 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 %21
%23 = load i8*, i8** %22
%24 = icmp eq i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %27
27: ; preds = %25, %20
%28 = add nuw nsw i64 %21, 1
%29 = icmp ult i64 %21, 15
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 %28
%32 = load i8*, i8** %31
%33 = icmp eq i8* %32, null
br i1 %33, label %36, label %34
34: ; preds = %30
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34, %30, %27
%37 = icmp eq i64 %28, 16
br i1 %37, label %38, label %20
38: ; preds = %36, %17, %14, %2
%39 = phi i32 [ %18, %17 ], [ %15, %14 ], [ %12, %2 ], [ 0, %36 ]
ret i32 %39
}