#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 /*<<< orphan*/ printf(char *);
int strlen(char *);
int imbalancedParentheses(char *s) {
  int i;
  int lpc = 0;
  int rpc = 0;
  for (i = 0; i < strlen(s); i++) {
    if (s[i] == '(')
      lpc++;
    if (s[i] == ')')
      rpc++;
  }
  if (rpc > lpc)
    printf("Imbalanced parentheses error. Too many right parentheses.\n");
  else if (rpc < lpc)
    printf("Imbalanced parentheses error. Too many left parentheses.\n");
  return rpc != lpc;
}


x86 assembly (clang, -O0):
<imbalancedParentheses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11ac <imbalancedParentheses+0x8c>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x28,%eax
jne    117b <imbalancedParentheses+0x5b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x29,%eax
jne    1199 <imbalancedParentheses+0x79>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119e <imbalancedParentheses+0x7e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1141 <imbalancedParentheses+0x21>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    11c9 <imbalancedParentheses+0xa9>
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
jmp    11e6 <imbalancedParentheses+0xc6>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e1 <imbalancedParentheses+0xc1>
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
jmp    11e6 <imbalancedParentheses+0xc6>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imbalancedParentheses>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
test   %eax,%eax
jle    1179 <imbalancedParentheses+0x59>
xor    %ebp,%ebp
xor    %r15d,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r14,%rbp,1),%eax
xor    %ecx,%ecx
cmp    $0x28,%al
sete   %cl
add    %ecx,%ebx
xor    %ecx,%ecx
cmp    $0x29,%al
sete   %cl
add    %ecx,%r15d
add    $0x1,%rbp
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1140 <imbalancedParentheses+0x20>
cmp    %ebx,%r15d
jbe    1180 <imbalancedParentheses+0x60>
lea    0xec2(%rip),%rdi
jmp    1189 <imbalancedParentheses+0x69>
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    118e <imbalancedParentheses+0x6e>
jae    118e <imbalancedParentheses+0x6e>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
cmp    %ebx,%r15d
setne  %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [59 x i8] c"Imbalanced parentheses error. Too many right parentheses.\0A\00"
@.str.1 = [58 x i8] c"Imbalanced parentheses error. Too many left parentheses.\0A\00"
define i32 @imbalancedParentheses(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %3
br label %6
6: ; preds = %34, %1
%7 = load i32, i32* %3
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %37
11: ; preds = %6
%12 = load i8*, i8** %2
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 40
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %22
22: ; preds = %19, %11
%23 = load i8*, i8** %2
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 41
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %33
33: ; preds = %30, %22
br label %34
34: ; preds = %33
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %6
37: ; preds = %6
%38 = load i32, i32* %5
%39 = load i32, i32* %4
%40 = icmp sgt i32 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
br label %50
43: ; preds = %37
%44 = load i32, i32* %5
%45 = load i32, i32* %4
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
br label %49
49: ; preds = %47, %43
br label %50
50: ; preds = %49, %41
%51 = load i32, i32* %5
%52 = load i32, i32* %4
%53 = icmp ne i32 %51, %52
%54 = zext i1 %53 to i32
ret i32 %54
}

LLVM IR (-O2):
@str = [57 x i8] c"Imbalanced parentheses error. Too many left parentheses.\00"
@str.2 = [58 x i8] c"Imbalanced parentheses error. Too many right parentheses.\00"
define i32 @imbalancedParentheses(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %27
4: ; preds = %1, %4
%5 = phi i64 [ %16, %4 ], [ 0, %1 ]
%6 = phi i32 [ %15, %4 ], [ 0, %1 ]
%7 = phi i32 [ %12, %4 ], [ 0, %1 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %5
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 40
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %7, %11
%13 = icmp eq i8 %9, 41
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %6, %14
%16 = add nuw nsw i64 %5, 1
%17 = tail call i32 @strlen(i8* %0)
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %4, label %20
20: ; preds = %4
%21 = icmp ugt i32 %15, %12
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = icmp ult i32 %15, %12
br i1 %23, label %24, label %27
24: ; preds = %22, %20
%25 = phi i8* [ getelementptr inbounds ([58 x i8], [58 x i8]* @str.2, i64 0, i64 0), %20 ], [ getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0), %22 ]
%26 = tail call i32 @puts(i8* dereferenceable(1) %25)
br label %27
27: ; preds = %24, %1, %22
%28 = phi i32 [ %15, %22 ], [ 0, %1 ], [ %15, %24 ]
%29 = phi i32 [ %12, %22 ], [ 0, %1 ], [ %12, %24 ]
%30 = icmp ne i32 %28, %29
%31 = zext i1 %30 to i32
ret i32 %31
}