#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 */
scalar_t__ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
const char *ReadVal(FILE *fp, char *buf, const size_t bufSize) {
  size_t idx = 0;
  char c = 0;
  memset(buf, 0, sizeof(char) * bufSize);
  while (idx < bufSize) {
    if (feof(fp)) {
      return buf;
    }
    c = fgetc(fp);
    if ((c == ' ') || (c == '\n')) {
      return buf;
    }
    buf[idx++] = c;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<ReadVal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movb   $0x0,-0x29(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11e4 <ReadVal+0xb4>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     1193 <ReadVal+0x63>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ec <ReadVal+0xbc>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
cmp    $0x20,%eax
je     11b9 <ReadVal+0x89>
movsbl -0x29(%rbp),%eax
cmp    $0xa,%eax
jne    11c6 <ReadVal+0x96>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ec <ReadVal+0xbc>
mov    -0x29(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x28(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    1165 <ReadVal+0x35>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadVal>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
test   %r15,%r15
je     118a <ReadVal+0x5a>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    118d <ReadVal+0x5d>
mov    %r12,%rdi
call   1040 <fgetc@plt>
cmp    $0xa,%al
je     118d <ReadVal+0x5d>
cmp    $0x20,%al
je     118d <ReadVal+0x5d>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <ReadVal+0x30>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @ReadVal(i32* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8
store i32* %0, i32** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64 0, i64* %8
store i8 0, i8* %9
%10 = load i8*, i8** %6
%11 = load i64, i64* %7
%12 = mul i64 1, %11
%13 = trunc i64 %12 to i32
%14 = call i32 @memset(i8* %10, i32 0, i32 %13)
br label %15
15: ; preds = %37, %3
%16 = load i64, i64* %8
%17 = load i64, i64* %7
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %43
19: ; preds = %15
%20 = load i32*, i32** %5
%21 = call i64 @feof(i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = load i8*, i8** %6
store i8* %24, i8** %4
br label %44
25: ; preds = %19
%26 = load i32*, i32** %5
%27 = call signext i8 @fgetc(i32* %26)
store i8 %27, i8* %9
%28 = load i8, i8* %9
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 32
br i1 %30, label %35, label %31
31: ; preds = %25
%32 = load i8, i8* %9
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %37
35: ; preds = %31, %25
%36 = load i8*, i8** %6
store i8* %36, i8** %4
br label %44
37: ; preds = %31
%38 = load i8, i8* %9
%39 = load i8*, i8** %6
%40 = load i64, i64* %8
%41 = add i64 %40, 1
store i64 %41, i64* %8
%42 = getelementptr inbounds i8, i8* %39, i64 %40
store i8 %38, i8* %42
br label %15
43: ; preds = %15
store i8* null, i8** %4
br label %44
44: ; preds = %43, %35, %23
%45 = load i8*, i8** %4
ret i8* %45
}

LLVM IR (-O2):
define i8* @ReadVal(i32* nocapture %0, i8* %1, i64 %2) {
%4 = trunc i64 %2 to i32
%5 = tail call i32 @memset(i8* %1, i32 0, i32 %4)
%6 = icmp eq i64 %2, 0
br i1 %6, label %17, label %7
7: ; preds = %3, %13
%8 = phi i64 [ %14, %13 ], [ 0, %3 ]
%9 = tail call i64 @feof(i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = tail call signext i8 @fgetc(i32* %0)
switch i8 %12, label %13 [
i8 32, label %17
i8 10, label %17
]
13: ; preds = %11
%14 = add nuw i64 %8, 1
%15 = getelementptr inbounds i8, i8* %1, i64 %8
store i8 %12, i8* %15
%16 = icmp eq i64 %14, %2
br i1 %16, label %17, label %7
17: ; preds = %7, %11, %11, %13, %3
%18 = phi i8* [ null, %3 ], [ null, %13 ], [ %1, %11 ], [ %1, %11 ], [ %1, %7 ]
ret i8* %18
}