#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 */
char fgetc(int /*<<< orphan*/ *);
scalar_t__ isspace(char);
char *readTOspace(FILE *file, char *buff, int size) {
  if (size < 1) {
    return NULL;
  }
  if (file == NULL) {
    return NULL;
  }
  if (buff) {
    int idx = 0;
    char c = 0;
    while ((c = fgetc(file)) != -1) {
      if (isspace(c)) {
        return buff;
      } else {
        buff[idx] = c;
        idx++;
      }
      if (idx >= size) {
        return NULL;
      }
    }
    return NULL;
  } else {
    return NULL;
  }
}


x86 assembly (clang, -O0):
<readTOspace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    114a <readTOspace+0x2a>
movq   $0x0,-0x8(%rbp)
jmp    11fa <readTOspace+0xda>
cmpq   $0x0,-0x10(%rbp)
jne    1162 <readTOspace+0x42>
movq   $0x0,-0x8(%rbp)
jmp    11fa <readTOspace+0xda>
cmpq   $0x0,-0x18(%rbp)
je     11f2 <readTOspace+0xd2>
movl   $0x0,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     11e5 <readTOspace+0xc5>
movsbl -0x21(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11b0 <readTOspace+0x90>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11fa <readTOspace+0xda>
mov    -0x21(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     11e0 <readTOspace+0xc0>
movq   $0x0,-0x8(%rbp)
jmp    11fa <readTOspace+0xda>
jmp    1178 <readTOspace+0x58>
movq   $0x0,-0x8(%rbp)
jmp    11fa <readTOspace+0xda>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readTOspace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rsi,%rsi
je     117d <readTOspace+0x5d>
mov    %rdi,%r12
test   %rdi,%rdi
je     117d <readTOspace+0x5d>
test   %edx,%edx
jle    117d <readTOspace+0x5d>
mov    %rsi,%r15
mov    %edx,%r13d
xor    %r14d,%r14d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <fgetc@plt>
cmp    $0xff,%al
je     117d <readTOspace+0x5d>
mov    %eax,%ebx
movsbl %al,%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    117a <readTOspace+0x5a>
mov    %bl,(%r15,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1150 <readTOspace+0x30>
jmp    117d <readTOspace+0x5d>
mov    %r15,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @readTOspace(i32* %0, i8* writeonly %1, i32 %2) {
%4 = icmp slt i32 %2, 1
%5 = icmp eq i32* %0, null
%6 = or i1 %5, %4
%7 = icmp eq i8* %1, null
%8 = or i1 %7, %6
br i1 %8, label %22, label %9
9: ; preds = %3
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %9, %18
%12 = phi i64 [ 0, %9 ], [ %20, %18 ]
%13 = tail call signext i8 @fgetc(i32* %0)
%14 = icmp eq i8 %13, -1
br i1 %14, label %22, label %15
15: ; preds = %11
%16 = tail call i64 @isspace(i8 signext %13)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = getelementptr inbounds i8, i8* %1, i64 %12
store i8 %13, i8* %19
%20 = add nuw nsw i64 %12, 1
%21 = icmp eq i64 %20, %10
br i1 %21, label %22, label %11
22: ; preds = %15, %18, %11, %3
%23 = phi i8* [ null, %3 ], [ null, %11 ], [ null, %18 ], [ %1, %15 ]
ret i8* %23
}