#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*/ fgets(char *, int, int /*<<< orphan*/);
scalar_t__ isformed(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  char s[80];
  puts("Enter an expression to verify well-formedness:");
  fgets(s, 80, stdin);
  s[strlen(s) - 1] = '\0';
  printf("Expression is %s-formed.\n", isformed(s) ? "well" : "ill");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
lea    -0x60(%rbp),%rdi
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1060 <fgets@plt>
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rdi
call   1070 <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>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x50,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1070 <isformed@plt>
test   %rax,%rax
lea    0xeb3(%rip),%rax
lea    0xea7(%rip),%rsi
cmove  %rax,%rsi
lea    0xe82(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Enter an expression to verify well-formedness:\00"
@stdin = global i32 0
@.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"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x 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 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %4, i32 80, i32 %5)
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%8 = call i32 @strlen(i8* %7)
%9 = sub nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %10
store i8 0, i8* %11
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%13 = call i64 @isformed(i8* %12)
%14 = icmp ne i64 %13, 0
%15 = zext i1 %14 to i64
%16 = select i1 %14, 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)
%17 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %16)
ret i32 0
}

LLVM IR (-O2):
@.str = [47 x i8] c"Enter an expression to verify well-formedness:\00"
@stdin = global i32 0
@.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"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %2, i32 80, i32 %4)
%6 = call i32 @strlen(i8* %2)
%7 = add nsw i32 %6, -1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %8
store i8 0, i8* %9
%10 = call i64 @isformed(i8* %2)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, 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)
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %12)
ret i32 0
}