#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int getfield(FILE *stream, char *buffer, int delim) {
  int count = 0;
  int c;
  for (; (c = getc(stream)), (c != EOF && c != delim);) {
    if (c == '\r')
      continue;
    if (++count >= 120 - 1) {
      fprintf(stderr, "field longer than expected, increase FIELDLEN\n");
      exit(1);
    }
    *buffer++ = c;
  }
  if (c == EOF)
    return 0;
  *buffer = '\0';
  return 1;
}


x86 assembly (clang, -O0):
<getfield>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
mov    0x2e86(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x25(%rbp)
je     1179 <getfield+0x49>
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1189 <getfield+0x59>
jmp    11e4 <getfield+0xb4>
cmpl   $0xd,-0x24(%rbp)
jne    1198 <getfield+0x68>
jmp    114a <getfield+0x1a>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmp    $0x77,%eax
jl     11c9 <getfield+0x99>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    114a <getfield+0x1a>
mov    -0x24(%rbp),%eax
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%eax
jne    1202 <getfield+0xd2>
movl   $0x0,-0x4(%rbp)
jmp    1210 <getfield+0xe0>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfield>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %r15d,%r15d
mov    0x2e9e(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <getc@plt>
mov    (%r12),%edx
cmp    %ebp,%eax
je     117c <getfield+0x4c>
cmp    %edx,%eax
je     117c <getfield+0x4c>
cmp    $0xd,%eax
je     1150 <getfield+0x20>
cmp    $0x76,%r15d
je     1196 <getfield+0x66>
add    $0x1,%r15d
mov    %al,(%r14)
add    $0x1,%r14
jmp    1150 <getfield+0x20>
xor    %ecx,%ecx
cmp    %edx,%eax
je     118b <getfield+0x5b>
movb   $0x0,(%r14)
mov    $0x1,%ecx
mov    %ecx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
@stderr = global i32 0
@.str = [47 x i8] c"field longer than expected, increase FIELDLEN\0A\00"
define i32 @getfield(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %10
10: ; preds = %34, %25, %3
%11 = load i32*, i32** %5
%12 = call i32 @getc(i32* %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load i32, i32* %9
%18 = load i32, i32* %7
%19 = icmp ne i32 %17, %18
br label %20
20: ; preds = %16, %10
%21 = phi i1 [ false, %10 ], [ %19, %16 ]
br i1 %21, label %22, label %39
22: ; preds = %20
%23 = load i32, i32* %9
%24 = icmp eq i32 %23, 13
br i1 %24, label %25, label %26
25: ; preds = %22
br label %10
26: ; preds = %22
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
%29 = icmp sge i32 %28, 119
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %26
%35 = load i32, i32* %9
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %6
store i8 %36, i8* %37
br label %10
39: ; preds = %20
%40 = load i32, i32* %9
%41 = load i32, i32* @EOF
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 0, i32* %4
br label %46
44: ; preds = %39
%45 = load i8*, i8** %6
store i8 0, i8* %45
store i32 1, i32* %4
br label %46
46: ; preds = %44, %43
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
@EOF = global i32 0
@stderr = global i32 0
@.str = [47 x i8] c"field longer than expected, increase FIELDLEN\0A\00"
define i32 @getfield(i32* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
br label %4
4: ; preds = %21, %3
%5 = phi i8* [ %24, %21 ], [ %1, %3 ]
%6 = phi i32 [ %22, %21 ], [ 0, %3 ]
br label %7
7: ; preds = %4, %13
%8 = tail call i32 @getc(i32* %0)
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
%11 = icmp ne i32 %8, %2
%12 = and i1 %11, %10
br i1 %12, label %13, label %25
13: ; preds = %7
%14 = icmp eq i32 %8, 13
br i1 %14, label %7, label %15
15: ; preds = %13
%16 = icmp eq i32 %6, 118
br i1 %16, label %17, label %21
17: ; preds = %15
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = add nuw nsw i32 %6, 1
%23 = trunc i32 %8 to i8
%24 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %23, i8* %5
br label %4
25: ; preds = %7
%26 = icmp eq i32 %8, %9
br i1 %26, label %28, label %27
27: ; preds = %25
store i8 0, i8* %5
br label %28
28: ; preds = %25, %27
%29 = phi i32 [ 1, %27 ], [ 0, %25 ]
ret i32 %29
}