#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__ calloc(int, int);
scalar_t__ checkParen(char *, int);
int /*<<< orphan*/ getc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ stdin;
int main() {
  int n, cs, i;
  char *paren;
  printf("Enter any non-zero positive number for parentheses checking code "
         "segment to run:");
  scanf("%d", &n);
  if (n) {
    printf("Enter the size of sequence of parentheses:\n");
    scanf("%d", &cs);
    getc(stdin);
    if (cs % 2 == 1) {
      printf("You cannot have balanced parentheses with odd number of "
             "parentheses!\n");
    } else {
      paren = (char *)calloc(cs + 1, sizeof(char));
      i = 0;
      while (i <= cs) {
        scanf("%c", &paren[i]);
        ++i;
      }
      if (checkParen(paren, cs)) {
        printf("The sequence is a balanced parentheses sequence.\n");
      } else {
        printf("The sequence is not a balanced parentheses sequence.\n");
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    0xedf(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
je     1263 <main+0x113>
lea    0xec6(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb7(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1070 <getc@plt>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    11d8 <main+0x88>
lea    0xeb2(%rip),%rdi
call   1040 <printf@plt>
jmp    125e <main+0x10e>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1226 <main+0xd6>
mov    -0x18(%rbp),%rsi
movslq -0x10(%rbp),%rax
add    %rax,%rsi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f3 <main+0xa3>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <checkParen@plt>
cmp    $0x0,%rax
je     124d <main+0xfd>
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
jmp    1259 <main+0x109>
lea    0xea7(%rip),%rdi
call   1040 <printf@plt>
jmp    125e <main+0x10e>
jmp    1263 <main+0x113>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe90(%rip),%rdi
call   1050 <printf@plt>
lea    0xed5(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
je     1252 <main+0xf2>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
lea    0xeab(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1080 <getc@plt>
mov    0x8(%rsp),%edi
mov    %edi,%eax
shr    $0x1f,%eax
add    %edi,%eax
and    $0xfffffffe,%eax
mov    %edi,%ecx
sub    %eax,%ecx
cmp    $0x1,%ecx
jne    11e0 <main+0x80>
lea    0xf0a(%rip),%rdi
jmp    124d <main+0xed>
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
mov    0x8(%rsp),%esi
test   %esi,%esi
js     1230 <main+0xd0>
mov    $0xffffffffffffffff,%rbx
lea    0xe4e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
lea    (%r15,%rbx,1),%rsi
add    $0x1,%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <scanf@plt>
movslq 0x8(%rsp),%rsi
add    $0x1,%rbx
cmp    %rsi,%rbx
jl     1210 <main+0xb0>
mov    %r15,%rdi
call   1040 <checkParen@plt>
test   %rax,%rax
lea    0xe40(%rip),%rax
lea    0xe6e(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [81 x i8] c"Enter any non-zero positive number for parentheses checking code segment to run:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [44 x i8] c"Enter the size of sequence of parentheses:\0A\00"
@stdin = global i32 0
@.str.3 = [70 x i8] c"You cannot have balanced parentheses with odd number of parentheses!\0A\00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [50 x i8] c"The sequence is a balanced parentheses sequence.\0A\00"
@.str.6 = [54 x i8] c"The sequence is not a balanced parentheses sequence.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %48
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%13 = load i32, i32* @stdin
%14 = call i32 @getc(i32 %13)
%15 = load i32, i32* %3
%16 = srem i32 %15, 2
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0))
br label %47
20: ; preds = %10
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
%23 = call i64 @calloc(i32 %22, i32 1)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %5
store i32 0, i32* %4
br label %25
25: ; preds = %29, %20
%26 = load i32, i32* %4
%27 = load i32, i32* %3
%28 = icmp sle i32 %26, %27
br i1 %28, label %29, label %37
29: ; preds = %25
%30 = load i8*, i8** %5
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %25
37: ; preds = %25
%38 = load i8*, i8** %5
%39 = load i32, i32* %3
%40 = call i64 @checkParen(i8* %38, i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
br label %46
44: ; preds = %37
%45 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.6, i64 0, i64 0))
br label %46
46: ; preds = %44, %42
br label %47
47: ; preds = %46, %18
br label %48
48: ; preds = %47, %0
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@.str = [81 x i8] c"Enter any non-zero positive number for parentheses checking code segment to run:\00"
@.str.1 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.4 = [3 x i8] c"%c\00"
@str = [43 x i8] c"Enter the size of sequence of parentheses:\00"
@str.7 = [53 x i8] c"The sequence is not a balanced parentheses sequence.\00"
@str.8 = [49 x i8] c"The sequence is a balanced parentheses sequence.\00"
@str.9 = [69 x i8] c"You cannot have balanced parentheses with odd number of parentheses!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 0
br i1 %8, label %39, label %9
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%12 = load i32, i32* @stdin
%13 = call i32 @getc(i32 %12)
%14 = load i32, i32* %2
%15 = srem i32 %14, 2
%16 = icmp eq i32 %15, 1
br i1 %16, label %36, label %17
17: ; preds = %9
%18 = add nsw i32 %14, 1
%19 = call i64 @calloc(i32 %18, i32 1)
%20 = inttoptr i64 %19 to i8*
%21 = load i32, i32* %2
%22 = icmp slt i32 %21, 0
br i1 %22, label %31, label %23
23: ; preds = %17, %23
%24 = phi i64 [ %27, %23 ], [ 0, %17 ]
%25 = getelementptr inbounds i8, i8* %20, i64 %24
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %25)
%27 = add nuw nsw i64 %24, 1
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %24, %29
br i1 %30, label %23, label %31
31: ; preds = %23, %17
%32 = phi i32 [ %21, %17 ], [ %28, %23 ]
%33 = call i64 @checkParen(i8* %20, i32 %32)
%34 = icmp eq i64 %33, 0
%35 = select i1 %34, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @str.7, i64 0, i64 0), i8* getelementptr inbounds ([49 x i8], [49 x i8]* @str.8, i64 0, i64 0)
br label %36
36: ; preds = %31, %9
%37 = phi i8* [ getelementptr inbounds ([69 x i8], [69 x i8]* @str.9, i64 0, i64 0), %9 ], [ %35, %31 ]
%38 = call i32 @puts(i8* dereferenceable(1) %37)
br label %39
39: ; preds = %36, %0
ret i32 0
}