#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 getc(int /*<<< orphan*/ *);
void get_field(FILE *f, char *buf, size_t size) {
  int i = 0, c;
  do {
    c = getc(f);
    buf[i++] = c;
  } while (c != '\0' && i != size);
  getc(f);
}


x86 assembly (clang, -O0):
<get_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
xor    %eax,%eax
cmpl   $0x0,-0x20(%rbp)
mov    %al,-0x21(%rbp)
je     116e <get_field+0x5e>
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    112b <get_field+0x1b>
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_field>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
add    $0xffffffffffffffff,%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <getc@plt>
mov    %al,(%r15,%rbx,1)
test   %eax,%eax
je     114c <get_field+0x3c>
lea    0x1(%rbx),%rax
cmp    %rbx,%r14
mov    %rax,%rbx
jne    1130 <get_field+0x20>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <getc@plt>

LLVM IR (-O0):
define void @get_field(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 0, i32* %7
br label %9
9: ; preds = %27, %3
%10 = load i32*, i32** %4
%11 = call i32 @getc(i32* %10)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = trunc i32 %12 to i8
%14 = load i8*, i8** %5
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 1
store i32 %16, i32* %7
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
store i8 %13, i8* %18
br label %19
19: ; preds = %9
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = load i64, i64* %6
%26 = icmp ne i64 %24, %25
br label %27
27: ; preds = %22, %19
%28 = phi i1 [ false, %19 ], [ %26, %22 ]
br i1 %28, label %9, label %29
29: ; preds = %27
%30 = load i32*, i32** %4
%31 = call i32 @getc(i32* %30)
ret void
}

LLVM IR (-O2):
define void @get_field(i32* nocapture %0, i8* nocapture writeonly %1, i64 %2) {
br label %4
4: ; preds = %4, %3
%5 = phi i64 [ %8, %4 ], [ 0, %3 ]
%6 = tail call i32 @getc(i32* %0)
%7 = trunc i32 %6 to i8
%8 = add nuw i64 %5, 1
%9 = getelementptr inbounds i8, i8* %1, i64 %5
store i8 %7, i8* %9
%10 = icmp ne i32 %6, 0
%11 = icmp ne i64 %8, %2
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %4, label %13
13: ; preds = %4
%14 = tail call i32 @getc(i32* %0)
ret void
}