#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 /*<<< orphan*/ free(char *);
size_t getdelim(char **, size_t *, char, int /*<<< orphan*/ *);
int get_field(FILE *fp, char delim, char **f) {
  char *s = NULL;
  size_t n, z;
  z = getdelim(&s, &n, delim, fp);
  if (z == -1) {
    free(s);
    return -1;
  }
  s[z - 1] = '\0';
  *f = s;
  return 0;
}


x86 assembly (clang, -O0):
<get_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
movsbl %al,%edx
call   1040 <getdelim@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0xffffffffffffffff,-0x38(%rbp)
jne    1179 <get_field+0x59>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119b <get_field+0x7b>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_field>:
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %esi,%edx
mov    %rdi,%rcx
movq   $0x0,(%rsp)
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1040 <getdelim@plt>
mov    (%rsp),%rdi
cmp    $0xffffffffffffffff,%rax
je     115c <get_field+0x3c>
movb   $0x0,-0x1(%rax,%rdi,1)
mov    (%rsp),%rax
mov    %rax,(%rbx)
xor    %eax,%eax
jmp    1166 <get_field+0x46>
call   1030 <free@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @get_field(i32* %0, i8 signext %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
store i32* %0, i32** %5
store i8 %1, i8* %6
store i8** %2, i8*** %7
store i8* null, i8** %8
%11 = load i8, i8* %6
%12 = load i32*, i32** %5
%13 = call i64 @getdelim(i8** %8, i64* %9, i8 signext %11, i32* %12)
store i64 %13, i64* %10
%14 = load i64, i64* %10
%15 = icmp eq i64 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i8*, i8** %8
%18 = call i32 @free(i8* %17)
store i32 -1, i32* %4
br label %26
19: ; preds = %3
%20 = load i8*, i8** %8
%21 = load i64, i64* %10
%22 = sub i64 %21, 1
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 0, i8* %23
%24 = load i8*, i8** %8
%25 = load i8**, i8*** %7
store i8* %24, i8** %25
store i32 0, i32* %4
br label %26
26: ; preds = %19, %16
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
define i32 @get_field(i32* %0, i8 signext %1, i8** nocapture writeonly %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = bitcast i64* %5 to i8*
%8 = call i64 @getdelim(i8** %4, i64* %5, i8 signext %1, i32* %0)
%9 = icmp eq i64 %8, -1
%10 = load i8*, i8** %4
br i1 %9, label %11, label %13
11: ; preds = %3
%12 = call i32 @free(i8* %10)
br label %17
13: ; preds = %3
%14 = add i64 %8, -1
%15 = getelementptr inbounds i8, i8* %10, i64 %14
store i8 0, i8* %15
%16 = load i8*, i8** %4
store i8* %16, i8** %2
br label %17
17: ; preds = %13, %11
%18 = phi i32 [ -1, %11 ], [ 0, %13 ]
ret i32 %18
}