#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 */
#define EOF 128
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ perror(char *);
void *realloc(char *, size_t);
char *get_field(FILE *f, char *delim) {
  char *s;
  size_t len;
  s = NULL;
  len = 0;
  for (;;) {
    int c;
    void *x;
    x = realloc(s, len + 1);
    if (x == NULL) {
      perror("realloc");
      free(s);
      return NULL;
    }
    s = x;
    c = fgetc(f);
    switch (c) {
    case EOF:
      *delim = '\0';
      goto done;
    case '\n':
    case '\t':
      *delim = c;
      goto done;
    }
    s[len] = c;
    len++;
  }
done:
  s[len] = '\0';
  return s;
}


x86 assembly (clang, -O0):
<get_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
call   1050 <realloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11a2 <get_field+0x62>
lea    0xe79(%rip),%rdi
call   1060 <perror@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1231 <get_field+0xf1>
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
add    $0xfffffff7,%eax
sub    $0x2,%eax
jb     11ec <get_field+0xac>
jmp    11cd <get_field+0x8d>
mov    -0x3c(%rbp),%eax
sub    $0x80,%eax
jne    11fc <get_field+0xbc>
jmp    11e0 <get_field+0xa0>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    121d <get_field+0xdd>
mov    -0x2c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
jmp    121d <get_field+0xdd>
mov    -0x2c(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1160 <get_field+0x20>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_field>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    $0x1,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11d0 <get_field+0x80>
mov    %rax,%r15
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1040 <fgetc@plt>
lea    -0x9(%rax),%ecx
cmp    $0x2,%ecx
jb     11ba <get_field+0x6a>
cmp    $0x80,%eax
je     11b8 <get_field+0x68>
mov    %al,-0x2(%r15,%rbx,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <realloc@plt>
mov    %r15,%r13
add    $0x1,%rbx
mov    %rax,%r15
test   %rax,%rax
jne    1180 <get_field+0x30>
jmp    11d3 <get_field+0x83>
xor    %eax,%eax
mov    %al,(%r14)
movb   $0x0,-0x2(%r15,%rbx,1)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %r13d,%r13d
lea    0xe26(%rip),%rdi
call   1070 <perror@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
jmp    11c3 <get_field+0x73>

LLVM IR (-O0):
@.str = [8 x i8] c"realloc\00"
define i8* @get_field(i32* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* null, i8** %6
store i64 0, i64* %7
br label %10
10: ; preds = %32, %2
%11 = load i8*, i8** %6
%12 = load i64, i64* %7
%13 = add i64 %12, 1
%14 = call i8* @realloc(i8* %11, i64 %13)
store i8* %14, i8** %9
%15 = load i8*, i8** %9
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %6
%20 = call i32 @free(i8* %19)
store i8* null, i8** %3
br label %45
21: ; preds = %10
%22 = load i8*, i8** %9
store i8* %22, i8** %6
%23 = load i32*, i32** %4
%24 = call i32 @fgetc(i32* %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
switch i32 %25, label %32 [
i32 128, label %26
i32 10, label %28
i32 9, label %28
]
26: ; preds = %21
%27 = load i8*, i8** %5
store i8 0, i8* %27
br label %40
28: ; preds = %21, %21
%29 = load i32, i32* %8
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %5
store i8 %30, i8* %31
br label %40
32: ; preds = %21
%33 = load i32, i32* %8
%34 = trunc i32 %33 to i8
%35 = load i8*, i8** %6
%36 = load i64, i64* %7
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8 %34, i8* %37
%38 = load i64, i64* %7
%39 = add i64 %38, 1
store i64 %39, i64* %7
br label %10
40: ; preds = %28, %26
%41 = load i8*, i8** %6
%42 = load i64, i64* %7
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8 0, i8* %43
%44 = load i8*, i8** %6
store i8* %44, i8** %3
br label %45
45: ; preds = %40, %17
%46 = load i8*, i8** %3
ret i8* %46
}

LLVM IR (-O2):
@.str = [8 x i8] c"realloc\00"
define noalias i8* @get_field(i32* nocapture %0, i8* nocapture writeonly %1) {
%3 = tail call dereferenceable_or_null(1) i8* @malloc(i64 1)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %9
5: ; preds = %16, %2
%6 = phi i8* [ null, %2 ], [ %10, %16 ]
%7 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @free(i8* %6)
br label %25
9: ; preds = %2, %16
%10 = phi i8* [ %20, %16 ], [ %3, %2 ]
%11 = phi i64 [ %19, %16 ], [ 1, %2 ]
%12 = phi i64 [ %11, %16 ], [ 0, %2 ]
%13 = tail call i32 @fgetc(i32* %0)
switch i32 %13, label %16 [
i32 128, label %22
i32 10, label %14
i32 9, label %14
]
14: ; preds = %9, %9
%15 = trunc i32 %13 to i8
br label %22
16: ; preds = %9
%17 = trunc i32 %13 to i8
%18 = getelementptr inbounds i8, i8* %10, i64 %12
store i8 %17, i8* %18
%19 = add i64 %11, 1
%20 = tail call i8* @realloc(i8* %10, i64 %19)
%21 = icmp eq i8* %20, null
br i1 %21, label %5, label %9
22: ; preds = %9, %14
%23 = phi i8 [ %15, %14 ], [ 0, %9 ]
store i8 %23, i8* %1
%24 = getelementptr inbounds i8, i8* %10, i64 %12
store i8 0, i8* %24
br label %25
25: ; preds = %5, %22
%26 = phi i8* [ null, %5 ], [ %10, %22 ]
ret i8* %26
}