#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
scalar_t__ isspace(char);
scalar_t__ malloc(int);
void readstring(FILE *fp, char **str) {
  int i = 0, j = 0;
  char c;
  *str = NULL;
  while (!feof(fp)) {
    if (!fread(&c, 1, 1, fp))
      continue;
    if (isspace(c))
      break;
    i++;
  }
  if (i == 0)
    return;
  *str = (char *)malloc(sizeof(char) * (i + 1));
  fseek(fp, -i - 1, SEEK_CUR);
  for (j = 0; j < i; j++)
    fread((*str + j), 1, 1, fp);
  *(*str + i) = '\0';
  return;
}


x86 assembly (clang, -O0):
<readstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1197 <readstring+0x47>
jmp    11df <readstring+0x8f>
mov    -0x8(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%eax
jne    11b9 <readstring+0x69>
jmp    1179 <readstring+0x29>
movsbl -0x19(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11d1 <readstring+0x81>
jmp    11df <readstring+0x8f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1179 <readstring+0x29>
cmpl   $0x0,-0x14(%rbp)
jne    11ee <readstring+0x9e>
jmp    1273 <readstring+0x123>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
sub    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    0x2dca(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1264 <readstring+0x114>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    122c <readstring+0xdc>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readstring>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
movq   $0x0,(%rsi)
xor    %r13d,%r13d
lea    0xf(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    11ba <readstring+0x6a>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     1180 <readstring+0x30>
movsbl 0xf(%rsp),%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    11ba <readstring+0x6a>
add    $0x1,%r13
jmp    1180 <readstring+0x30>
test   %r13d,%r13d
je     121a <readstring+0xca>
lea    0x1(%r13),%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
mov    %r13d,%esi
not    %esi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
call   1070 <fseek@plt>
mov    %r13d,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    (%r14),%rdi
add    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
add    $0x1,%rbx
add    $0xffffffffffffffff,%r13
jne    11f0 <readstring+0xa0>
mov    (%r14),%rax
movb   $0x0,(%rax,%r15,1)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_CUR = global i32 0
define void @readstring(i32* %0, i8** %1) {
%3 = alloca i32*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i32* %0, i32** %3
store i8** %1, i8*** %4
store i32 0, i32* %5
store i32 0, i32* %6
%8 = load i8**, i8*** %4
store i8* null, i8** %8
br label %9
9: ; preds = %24, %18, %2
%10 = load i32*, i32** %3
%11 = call i32 @feof(i32* %10)
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %27
14: ; preds = %9
%15 = load i32*, i32** %3
%16 = call i32 @fread(i8* %7, i32 1, i32 1, i32* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %14
br label %9
19: ; preds = %14
%20 = load i8, i8* %7
%21 = call i64 @isspace(i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
br label %27
24: ; preds = %19
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %9
27: ; preds = %23, %9
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %27
br label %67
31: ; preds = %27
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = mul i64 1, %34
%36 = trunc i64 %35 to i32
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to i8*
%39 = load i8**, i8*** %4
store i8* %38, i8** %39
%40 = load i32*, i32** %3
%41 = load i32, i32* %5
%42 = sub nsw i32 0, %41
%43 = sub nsw i32 %42, 1
%44 = load i32, i32* @SEEK_CUR
%45 = call i32 @fseek(i32* %40, i32 %43, i32 %44)
store i32 0, i32* %6
br label %46
46: ; preds = %58, %31
%47 = load i32, i32* %6
%48 = load i32, i32* %5
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %61
50: ; preds = %46
%51 = load i8**, i8*** %4
%52 = load i8*, i8** %51
%53 = load i32, i32* %6
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i32*, i32** %3
%57 = call i32 @fread(i8* %55, i32 1, i32 1, i32* %56)
br label %58
58: ; preds = %50
%59 = load i32, i32* %6
%60 = add nsw i32 %59, 1
store i32 %60, i32* %6
br label %46
61: ; preds = %46
%62 = load i8**, i8*** %4
%63 = load i8*, i8** %62
%64 = load i32, i32* %5
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 0, i8* %66
br label %67
67: ; preds = %61, %30
ret void
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
define void @readstring(i32* nocapture %0, i8** nocapture %1) {
%3 = alloca i8
store i8* null, i8** %1
br label %4
4: ; preds = %16, %2
%5 = phi i32 [ %17, %16 ], [ 0, %2 ]
br label %6
6: ; preds = %4, %9
%7 = tail call i32 @feof(i32* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %6, label %12
12: ; preds = %9
%13 = load i8, i8* %3
%14 = tail call i64 @isspace(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = add nuw nsw i32 %5, 1
br label %4
18: ; preds = %12, %6
%19 = icmp eq i32 %5, 0
br i1 %19, label %38, label %20
20: ; preds = %18
%21 = add nuw nsw i32 %5, 1
%22 = tail call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %1
%24 = xor i32 %5, -1
%25 = load i32, i32* @SEEK_CUR
%26 = tail call i32 @fseek(i32* %0, i32 %24, i32 %25)
%27 = zext i32 %5 to i64
br label %28
28: ; preds = %20, %28
%29 = phi i64 [ 0, %20 ], [ %33, %28 ]
%30 = load i8*, i8** %1
%31 = getelementptr inbounds i8, i8* %30, i64 %29
%32 = tail call i32 @fread(i8* %31, i32 1, i32 1, i32* %0)
%33 = add nuw nsw i64 %29, 1
%34 = icmp eq i64 %33, %27
br i1 %34, label %35, label %28
35: ; preds = %28
%36 = load i8*, i8** %1
%37 = getelementptr inbounds i8, i8* %36, i64 %27
store i8 0, i8* %37
br label %38
38: ; preds = %18, %35
ret void
}