#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 NULL;
    }
    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>
movq   $0x0,-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    118a <ReadVal+0x5a>
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 = %36, %3
%16 = load i64, i64* %8
%17 = load i64, i64* %7
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %42
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 %24
23: ; preds = %19
store i8* null, i8** %4
br label %43
24: ; preds = %19
%25 = load i32*, i32** %5
%26 = call signext i8 @fgetc(i32* %25)
store i8 %26, i8* %9
%27 = load i8, i8* %9
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 32
br i1 %29, label %34, label %30
30: ; preds = %24
%31 = load i8, i8* %9
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 10
br i1 %33, label %34, label %36
34: ; preds = %30, %24
%35 = load i8*, i8** %6
store i8* %35, i8** %4
br label %43
36: ; preds = %30
%37 = load i8, i8* %9
%38 = load i8*, i8** %6
%39 = load i64, i64* %8
%40 = add i64 %39, 1
store i64 %40, i64* %8
%41 = getelementptr inbounds i8, i8* %38, i64 %39
store i8 %37, i8* %41
br label %15
42: ; preds = %15
store i8* null, i8** %4
br label %43
43: ; preds = %42, %34, %23
%44 = load i8*, i8** %4
ret i8* %44
}

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 ], [ null, %7 ]
ret i8* %18
}