#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *getstr();
scalar_t__ isformed(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int main() {
  char *s;
  puts("Enter an expression to verify well-formedness:");
  if (!(s = getstr()))
    goto alocerr;
  printf("Expression is %s-formed.\n", isformed(s) ? "well" : "ill");
  free(s);
  return 0;
alocerr:
  fprintf(stderr, "Allocation Error!\n");
  return 12;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1060 <getstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1195 <main+0x35>
jmp    11d8 <main+0x78>
mov    -0x10(%rbp),%rdi
call   1080 <isformed@plt>
mov    %rax,%rcx
lea    0xea6(%rip),%rsi
lea    0xe9a(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe71(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f4 <main+0x94>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xc,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xe96(%rip),%rdi
call   1040 <puts@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <getstr@plt>
test   %rax,%rax
je     11b3 <main+0x53>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <isformed@plt>
test   %rax,%rax
lea    0xebc(%rip),%rax
lea    0xeb0(%rip),%rsi
cmove  %rax,%rsi
lea    0xe8b(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11cd <main+0x6d>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xc,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Enter an expression to verify well-formedness:\00"
@.str.1 = [26 x i8] c"Expression is %s-formed.\0A\00"
@.str.2 = [5 x i8] c"well\00"
@.str.3 = [4 x i8] c"ill\00"
@stderr = global i32 0
@.str.4 = [19 x i8] c"Allocation Error!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i32 @puts(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%4 = call i8* (...) @getstr()
store i8* %4, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %0
br label %16
7: ; preds = %0
%8 = load i8*, i8** %2
%9 = call i64 @isformed(i8* %8)
%10 = icmp ne i64 %9, 0
%11 = zext i1 %10 to i64
%12 = select i1 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0)
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %2
%15 = call i32 @free(i8* %14)
store i32 0, i32* %1
br label %19
16: ; preds = %6
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
store i32 12, i32* %1
br label %19
19: ; preds = %16, %7
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str = [47 x i8] c"Enter an expression to verify well-formedness:\00"
@.str.1 = [26 x i8] c"Expression is %s-formed.\0A\00"
@.str.2 = [5 x i8] c"well\00"
@.str.3 = [4 x i8] c"ill\00"
@stderr = global i32 0
@.str.4 = [19 x i8] c"Allocation Error!\0A\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%2 = tail call i8* (...) @getstr()
%3 = icmp eq i8* %2, null
br i1 %3, label %10, label %4
4: ; preds = %0
%5 = tail call i64 @isformed(i8* %2)
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = tail call i32 @free(i8* %2)
br label %13
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %13
13: ; preds = %10, %4
%14 = phi i32 [ 0, %4 ], [ 12, %10 ]
ret i32 %14
}