#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 wchar_t;
struct varstr {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int WEOF;
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetwc(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ read_data(int *, int);
struct varstr *varstr_init();
int *varstr_pack(struct varstr *);
int /*<<< orphan*/ *varstr_pushc(struct varstr *, int);
extern int read_input(FILE *fp, bool is_sentence) {
  struct varstr *buf = varstr_init();
  if (buf == NULL) {
    perror("init varstr in read_input()");
    return 2;
  }
  for (wchar_t c = fgetwc(fp); c != WEOF && c != L'\n'; c = fgetwc(fp)) {
    if (varstr_pushc(buf, c) == NULL)
      break;
  }
  if (ferror(fp)) {
    perror("reading file in read_input()");
    return 2;
  }
  wchar_t *str;
  if ((str = varstr_pack(buf)) == NULL) {
    perror("packing varstr in read_input()");
    return 2;
  }
  if (!read_data(str, is_sentence))
    return 2;
  free(str);
  return (feof(fp) ? 1 : 0);
}


x86 assembly (clang, -O0):
<read_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   1050 <varstr_init@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cd <read_input+0x3d>
lea    0xe44(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12dc <read_input+0x14c>
mov    -0x10(%rbp),%rdi
call   1070 <fgetwc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
mov    0x2dfb(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x31(%rbp)
je     11fa <read_input+0x6a>
cmpl   $0xa,-0x24(%rbp)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    120a <read_input+0x7a>
jmp    123b <read_input+0xab>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   10a0 <varstr_pushc@plt>
cmp    $0x0,%rax
jne    1225 <read_input+0x95>
jmp    123b <read_input+0xab>
jmp    122a <read_input+0x9a>
mov    -0x10(%rbp),%rdi
call   1070 <fgetwc@plt>
mov    %eax,-0x24(%rbp)
jmp    11d9 <read_input+0x49>
mov    -0x10(%rbp),%rdi
call   1060 <ferror@plt>
cmp    $0x0,%rax
je     1266 <read_input+0xd6>
lea    0xdc7(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12dc <read_input+0x14c>
mov    -0x20(%rbp),%rdi
call   1080 <varstr_pack@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1295 <read_input+0x105>
lea    0xdb5(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12dc <read_input+0x14c>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <read_data@plt>
cmp    $0x0,%eax
jne    12b6 <read_input+0x126>
movl   $0x2,-0x4(%rbp)
jmp    12dc <read_input+0x14c>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x10(%rbp),%rdi
call   1090 <feof@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_input>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <varstr_init@plt>
test   %rax,%rax
je     123a <read_input+0xaa>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1070 <fgetwc@plt>
cmp    $0xa,%eax
je     11f1 <read_input+0x61>
mov    0x2e1c(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    (%r15),%eax
je     11f1 <read_input+0x61>
mov    %rbp,%rdi
mov    %eax,%esi
call   10a0 <varstr_pushc@plt>
test   %rax,%rax
je     11f1 <read_input+0x61>
mov    %rbx,%rdi
call   1070 <fgetwc@plt>
cmp    $0xa,%eax
jne    11d0 <read_input+0x40>
mov    %rbx,%rdi
call   1060 <ferror@plt>
test   %rax,%rax
jne    1243 <read_input+0xb3>
mov    %rbp,%rdi
call   1080 <varstr_pack@plt>
test   %rax,%rax
je     124c <read_input+0xbc>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14d,%esi
call   1030 <read_data@plt>
test   %eax,%eax
je     1258 <read_input+0xc8>
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
jmp    125d <read_input+0xcd>
lea    0xdbf(%rip),%rdi
jmp    1253 <read_input+0xc3>
lea    0xdd2(%rip),%rdi
jmp    1253 <read_input+0xc3>
lea    0xde6(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.varstr = type { i32 }
@.str = [28 x i8] c"init varstr in read_input()\00"
@WEOF = global i32 0
@.str.1 = [29 x i8] c"reading file in read_input()\00"
@.str.2 = [31 x i8] c"packing varstr in read_input()\00"
define i32 @read_input(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca %struct.varstr*
%7 = alloca i32
%8 = alloca i32*
store i32* %0, i32** %4
store i32 %1, i32* %5
%9 = call %struct.varstr* (...) @varstr_init()
store %struct.varstr* %9, %struct.varstr** %6
%10 = load %struct.varstr*, %struct.varstr** %6
%11 = icmp eq %struct.varstr* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %3
br label %62
14: ; preds = %2
%15 = load i32*, i32** %4
%16 = call i32 @fgetwc(i32* %15)
store i32 %16, i32* %7
br label %17
17: ; preds = %33, %14
%18 = load i32, i32* %7
%19 = load i32, i32* @WEOF
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* %7
%23 = icmp ne i32 %22, 10
br label %24
24: ; preds = %21, %17
%25 = phi i1 [ false, %17 ], [ %23, %21 ]
br i1 %25, label %26, label %36
26: ; preds = %24
%27 = load %struct.varstr*, %struct.varstr** %6
%28 = load i32, i32* %7
%29 = call i32* @varstr_pushc(%struct.varstr* %27, i32 %28)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %32
31: ; preds = %26
br label %36
32: ; preds = %26
br label %33
33: ; preds = %32
%34 = load i32*, i32** %4
%35 = call i32 @fgetwc(i32* %34)
store i32 %35, i32* %7
br label %17
36: ; preds = %31, %24
%37 = load i32*, i32** %4
%38 = call i64 @ferror(i32* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %62
42: ; preds = %36
%43 = load %struct.varstr*, %struct.varstr** %6
%44 = call i32* @varstr_pack(%struct.varstr* %43)
store i32* %44, i32** %8
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %62
48: ; preds = %42
%49 = load i32*, i32** %8
%50 = load i32, i32* %5
%51 = call i32 @read_data(i32* %49, i32 %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %54, label %53
53: ; preds = %48
store i32 2, i32* %3
br label %62
54: ; preds = %48
%55 = load i32*, i32** %8
%56 = call i32 @free(i32* %55)
%57 = load i32*, i32** %4
%58 = call i64 @feof(i32* %57)
%59 = icmp ne i64 %58, 0
%60 = zext i1 %59 to i64
%61 = select i1 %59, i32 1, i32 0
store i32 %61, i32* %3
br label %62
62: ; preds = %54, %53, %46, %40, %12
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
%struct.varstr = type { i32 }
@.str = [28 x i8] c"init varstr in read_input()\00"
@WEOF = global i32 0
@.str.1 = [29 x i8] c"reading file in read_input()\00"
@.str.2 = [31 x i8] c"packing varstr in read_input()\00"
define i32 @read_input(i32* %0, i32 %1) {
%3 = tail call %struct.varstr* (...) @varstr_init()
%4 = icmp eq %struct.varstr* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %41
7: ; preds = %2
%8 = tail call i32 @fgetwc(i32* %0)
%9 = load i32, i32* @WEOF
%10 = icmp ne i32 %8, %9
%11 = icmp ne i32 %8, 10
%12 = and i1 %11, %10
br i1 %12, label %13, label %23
13: ; preds = %7, %17
%14 = phi i32 [ %18, %17 ], [ %8, %7 ]
%15 = tail call i32* @varstr_pushc(%struct.varstr* %3, i32 %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %23, label %17
17: ; preds = %13
%18 = tail call i32 @fgetwc(i32* %0)
%19 = load i32, i32* @WEOF
%20 = icmp ne i32 %18, %19
%21 = icmp ne i32 %18, 10
%22 = and i1 %21, %20
br i1 %22, label %13, label %23
23: ; preds = %17, %13, %7
%24 = tail call i64 @ferror(i32* %0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %41
28: ; preds = %23
%29 = tail call i32* @varstr_pack(%struct.varstr* %3)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %41
33: ; preds = %28
%34 = tail call i32 @read_data(i32* %29, i32 %1)
%35 = icmp eq i32 %34, 0
br i1 %35, label %41, label %36
36: ; preds = %33
%37 = tail call i32 @free(i32* %29)
%38 = tail call i64 @feof(i32* %0)
%39 = icmp ne i64 %38, 0
%40 = zext i1 %39 to i32
br label %41
41: ; preds = %31, %36, %33, %26, %5
%42 = phi i32 [ 2, %5 ], [ 2, %26 ], [ 2, %31 ], [ %40, %36 ], [ 2, %33 ]
ret i32 %42
}