#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 */
typedef int /*<<< orphan*/ input_string;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ check_corr_paren(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *readline(FILE *stream) {
  char input_string[256];
  static char exp_string[2048];
  exp_string[0] = '\0';
  do {
    if (fgets(input_string, sizeof(input_string), stream) == NULL)
      break;
    input_string[sizeof(input_string) - 1] = '\0';
    input_string[strlen(input_string) - 1] = ' ';
    strcat(exp_string, input_string);
    if (stream == stdin && check_corr_paren(exp_string) == 0)
      break;
  } while (1);
  return exp_string;
}


x86 assembly (clang, -O0):
<readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,0x2efa(%rip)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    117a <readline+0x3a>
jmp    11ed <readline+0xad>
movb   $0x0,-0x11(%rbp)
lea    -0x110(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x20,-0x110(%rbp,%rax,1)
20
lea    -0x110(%rbp),%rsi
lea    0x2eab(%rip),%rdi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%rax
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%rax
jne    11d9 <readline+0x99>
lea    0x2e8b(%rip),%rdi
call   1050 <check_corr_paren@plt>
cmp    $0x0,%rax
jne    11d9 <readline+0x99>
jmp    11ed <readline+0xad>
jmp    11de <readline+0x9e>
mov    $0x1,%al
test   $0x1,%al
jne    1156 <readline+0x16>
jmp    11ed <readline+0xad>
lea    0x2e5c(%rip),%rax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readline>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
movb   $0x0,0x2ef8(%rip)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11ca <readline+0x8a>
lea    0x2ed9(%rip),%r15
mov    0x2e6a(%rip),%r12
jmp    1195 <readline+0x55>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11ca <readline+0x8a>
movb   $0x0,0xff(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x20,-0x1(%rax,%rbx,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
cmp    %r14,(%r12)
jne    1180 <readline+0x40>
mov    %r15,%rdi
call   1050 <check_corr_paren@plt>
test   %rax,%rax
jne    1180 <readline+0x40>
lea    0x2e7f(%rip),%rax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@readline.exp_string = internal global [2048 x i8] zeroinitializer
@stdin = global i32* null
define i8* @readline(i32* %0) {
%2 = alloca i32*
%3 = alloca [256 x i8]
store i32* %0, i32** %2
store i8 0, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @readline.exp_string, i64 0, i64 0)
br label %4
4: ; preds = %27, %1
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = load i32*, i32** %2
%7 = call i32* @fgets(i8* %5, i32 256, i32* %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %4
br label %28
10: ; preds = %4
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 255
store i8 0, i8* %11
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %15
store i8 32, i8* %16
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%18 = call i32 @strcat(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @readline.exp_string, i64 0, i64 0), i8* %17)
%19 = load i32*, i32** %2
%20 = load i32*, i32** @stdin
%21 = icmp eq i32* %19, %20
br i1 %21, label %22, label %26
22: ; preds = %10
%23 = call i64 @check_corr_paren(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @readline.exp_string, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
br label %28
26: ; preds = %22, %10
br label %27
27: ; preds = %26
br i1 true, label %4, label %28
28: ; preds = %27, %25, %9
ret i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @readline.exp_string, i64 0, i64 0)
}

LLVM IR (-O2):
@readline.exp_string = internal global [2048 x i8] zeroinitializer
@stdin = global i32* null
define i8* @readline(i32* nocapture %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
store i8 0, i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @readline.exp_string, i64 0, i64 0)
%4 = call i32* @fgets(i8* %3, i32 256, i32* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %22, label %6
6: ; preds = %1
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 255
br label %8
8: ; preds = %6, %19
store i8 0, i8* %7
%9 = call i32 @strlen(i8* %3)
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %11
store i8 32, i8* %12
%13 = call i32 @strcat(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @readline.exp_string, i64 0, i64 0), i8* %3)
%14 = load i32*, i32** @stdin
%15 = icmp eq i32* %14, %0
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = call i64 @check_corr_paren(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @readline.exp_string, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %8, %16
%20 = call i32* @fgets(i8* %3, i32 256, i32* %0)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %8
22: ; preds = %19, %16, %1
ret i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @readline.exp_string, i64 0, i64 0)
}