#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 EOF;
int fgetc(int /*<<< orphan*/ *);
scalar_t__ is_whitespace(char);
int /*<<< orphan*/ skip_field(int /*<<< orphan*/ *);
int get_next_field(FILE *fd, char *str, const size_t len) {
  int success;
  int i;
  for (i = 0;; ++i) {
    int tmp_char = fgetc(fd);
    if (tmp_char == EOF) {
      str[i] = '\0';
      success = 2;
      break;
    } else if (is_whitespace((char)tmp_char)) {
      str[i] = '\0';
      success = 1;
      break;
    } else if (i == (int)len - 1) {
      str[i] = '\0';
      success = 3;
      skip_field(fd);
      break;
    } else {
      str[i] = (char)tmp_char;
    }
  }
  return success;
}


x86 assembly (clang, -O0):
<get_next_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e87(%rip),%rcx
cmp    (%rcx),%eax
jne    1181 <get_next_field+0x51>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x2,-0x1c(%rbp)
jmp    120e <get_next_field+0xde>
mov    -0x24(%rbp),%eax
movsbl %al,%edi
call   1040 <is_whitespace@plt>
cmp    $0x0,%rax
je     11ae <get_next_field+0x7e>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x1c(%rbp)
jmp    120e <get_next_field+0xde>
mov    -0x20(%rbp),%eax
mov    -0x18(%rbp),%rcx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11e1 <get_next_field+0xb1>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x3,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <skip_field@plt>
jmp    120e <get_next_field+0xde>
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11f6 <get_next_field+0xc6>
jmp    11fb <get_next_field+0xcb>
jmp    1200 <get_next_field+0xd0>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114b <get_next_field+0x1b>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_field>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <fgetc@plt>
mov    0x2e98(%rip),%r12
cmp    (%r12),%eax
jne    115a <get_next_field+0x2a>
xor    %eax,%eax
jmp    119d <get_next_field+0x6d>
mov    %eax,%ebp
add    $0xffffffff,%r13d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %bpl,%edi
call   1040 <is_whitespace@plt>
test   %rax,%rax
jne    11a9 <get_next_field+0x79>
cmp    %rbx,%r13
je     11b5 <get_next_field+0x85>
mov    %bpl,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
cmp    (%r12),%eax
jne    1170 <get_next_field+0x40>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    $0x2,%eax
jmp    11c7 <get_next_field+0x97>
movb   $0x0,(%r14,%rbx,1)
mov    $0x1,%eax
jmp    11c7 <get_next_field+0x97>
movb   $0x0,(%r14,%r13,1)
mov    %r15,%rdi
call   1050 <skip_field@plt>
mov    $0x3,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i32 @get_next_field(i32* %0, i8* nocapture writeonly %1, i64 %2) {
%4 = tail call i32 @fgetc(i32* %0)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = add i64 %2, 4294967295
%9 = and i64 %8, 4294967295
br label %15
10: ; preds = %29
%11 = and i64 %31, 4294967295
br label %12
12: ; preds = %10, %3
%13 = phi i64 [ 0, %3 ], [ %11, %10 ]
%14 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 0, i8* %14
br label %35
15: ; preds = %7, %29
%16 = phi i64 [ 0, %7 ], [ %31, %29 ]
%17 = phi i32 [ %4, %7 ], [ %32, %29 ]
%18 = trunc i32 %17 to i8
%19 = tail call i64 @is_whitespace(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %15
%22 = and i64 %16, 4294967295
%23 = getelementptr inbounds i8, i8* %1, i64 %22
store i8 0, i8* %23
br label %35
24: ; preds = %15
%25 = icmp eq i64 %16, %9
br i1 %25, label %26, label %29
26: ; preds = %24
%27 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 0, i8* %27
%28 = tail call i32 @skip_field(i32* %0)
br label %35
29: ; preds = %24
%30 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 %18, i8* %30
%31 = add nuw nsw i64 %16, 1
%32 = tail call i32 @fgetc(i32* %0)
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %10, label %15
35: ; preds = %12, %21, %26
%36 = phi i32 [ 3, %26 ], [ 1, %21 ], [ 2, %12 ]
ret i32 %36
}