#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 */
scalar_t__ is_balanced(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int failed = 0;
  if (!is_balanced("asdf")) {
    failed = -1;
    printf("failed on input \"asdf\"\n");
  }
  if (!is_balanced("({})")) {
    failed = -1;
    printf("failed on input \"({})\"\n");
  }
  char *str = "asdf(asdf{asdf{asdf}asdf[asdf(asdf)]})";
  if (!is_balanced(str)) {
    failed = -1;
    printf("failed on input \"%s\"\n", str);
  }
  if (is_balanced("(")) {
    failed = -1;
    printf("failed on input \"(\"\n");
  }
  if (is_balanced("a(sdf])")) {
    failed = -1;
    printf("failed on input \"a(sdf])\"\n");
  }
  return failed;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xec3(%rip),%rdi
call   1040 <is_balanced@plt>
cmp    $0x0,%rax
jne    1161 <main+0x41>
movl   $0xffffffff,-0x8(%rbp)
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb5(%rip),%rdi
call   1040 <is_balanced@plt>
cmp    $0x0,%rax
jne    118c <main+0x6c>
movl   $0xffffffff,-0x8(%rbp)
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea7(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <is_balanced@plt>
cmp    $0x0,%rax
jne    11c3 <main+0xa3>
movl   $0xffffffff,-0x8(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xead(%rip),%rdi
call   1040 <is_balanced@plt>
cmp    $0x0,%rax
je     11ee <main+0xce>
movl   $0xffffffff,-0x8(%rbp)
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe99(%rip),%rdi
call   1040 <is_balanced@plt>
cmp    $0x0,%rax
je     1219 <main+0xf9>
movl   $0xffffffff,-0x8(%rbp)
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
call   1050 <is_balanced@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    1155 <main+0x25>
lea    0xf06(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
lea    0xea9(%rip),%rdi
call   1050 <is_balanced@plt>
test   %rax,%rax
jne    1177 <main+0x47>
lea    0xefb(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
lea    0xe8c(%rip),%rdi
call   1050 <is_balanced@plt>
test   %rax,%rax
jne    11a2 <main+0x72>
lea    0xea2(%rip),%rdi
lea    0xe74(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
lea    0xe9e(%rip),%rdi
call   1050 <is_balanced@plt>
test   %rax,%rax
je     11c4 <main+0x94>
lea    0xedf(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
lea    0xe7e(%rip),%rdi
call   1050 <is_balanced@plt>
test   %rax,%rax
je     11e6 <main+0xb6>
lea    0xea3(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"asdf\00"
@.str.1 = [24 x i8] c"failed on input \22asdf\22\0A\00"
@.str.2 = [5 x i8] c"({})\00"
@.str.3 = [24 x i8] c"failed on input \22({})\22\0A\00"
@.str.4 = [39 x i8] c"asdf(asdf{asdf{asdf}asdf[asdf(asdf)]})\00"
@.str.5 = [22 x i8] c"failed on input \22%s\22\0A\00"
@.str.6 = [2 x i8] c"(\00"
@.str.7 = [21 x i8] c"failed on input \22(\22\0A\00"
@.str.8 = [8 x i8] c"a(sdf])\00"
@.str.9 = [27 x i8] c"failed on input \22a(sdf])\22\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %2
%4 = call i64 @is_balanced(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = icmp ne i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
store i32 -1, i32* %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i64 @is_balanced(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp ne i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
store i32 -1, i32* %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
store i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8** %3
%14 = load i8*, i8** %3
%15 = call i64 @is_balanced(i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
store i32 -1, i32* %2
%18 = load i8*, i8** %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %13
%21 = call i64 @is_balanced(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
store i32 -1, i32* %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = call i64 @is_balanced(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
store i32 -1, i32* %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [5 x i8] c"asdf\00"
@.str.2 = [5 x i8] c"({})\00"
@.str.4 = [39 x i8] c"asdf(asdf{asdf{asdf}asdf[asdf(asdf)]})\00"
@.str.5 = [22 x i8] c"failed on input \22%s\22\0A\00"
@.str.6 = [2 x i8] c"(\00"
@.str.8 = [8 x i8] c"a(sdf])\00"
@str = [23 x i8] c"failed on input \22asdf\22\00"
@str.10 = [23 x i8] c"failed on input \22({})\22\00"
@str.11 = [26 x i8] c"failed on input \22a(sdf])\22\00"
@str.12 = [20 x i8] c"failed on input \22(\22\00"
define i32 @main() {
%1 = tail call i64 @is_balanced(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = phi i32 [ 0, %0 ], [ -1, %3 ]
%7 = tail call i64 @is_balanced(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.10, i64 0, i64 0))
br label %11
11: ; preds = %9, %5
%12 = phi i32 [ %6, %5 ], [ -1, %9 ]
%13 = tail call i64 @is_balanced(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = phi i32 [ %12, %11 ], [ -1, %15 ]
%19 = tail call i64 @is_balanced(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.12, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
%24 = phi i32 [ -1, %21 ], [ %18, %17 ]
%25 = tail call i64 @is_balanced(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.11, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
%30 = phi i32 [ -1, %27 ], [ %24, %23 ]
ret i32 %30
}