#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 fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int RAWGET_get(unsigned char *buffer, int max, FILE *f) {
  unsigned char c;
  int count = 0;
  while (count < max) {
    if (fread(&c, 1, 1, f) == 1) {
      *buffer = c;
      buffer++;
      count++;
      if (c == '\n') {
        break;
      }
    } else
      break;
  }
  return count;
}


x86 assembly (clang, -O0):
<RAWGET_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1192 <RAWGET_get+0x82>
mov    -0x18(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    1188 <RAWGET_get+0x78>
mov    -0x19(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movzbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    1183 <RAWGET_get+0x73>
jmp    1192 <RAWGET_get+0x82>
jmp    118d <RAWGET_get+0x7d>
jmp    1192 <RAWGET_get+0x82>
jmp    112a <RAWGET_get+0x1a>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RAWGET_get>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%r13d
mov    %rdi,%r15
xor    %ebx,%ebx
test   %esi,%esi
cmovle %ebx,%r13d
lea    0xf(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %ebx,%r13d
je     1173 <RAWGET_get+0x63>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    1170 <RAWGET_get+0x60>
movzbl 0xf(%rsp),%eax
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    $0xa,%al
jne    1140 <RAWGET_get+0x30>
mov    %ebx,%r13d
mov    %r13d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @RAWGET_get(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %8
br label %9
9: ; preds = %30, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %31
13: ; preds = %9
%14 = load i32*, i32** %6
%15 = call i32 @fread(i8* %7, i32 1, i32 1, i32* %14)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %29
17: ; preds = %13
%18 = load i8, i8* %7
%19 = load i8*, i8** %4
store i8 %18, i8* %19
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
store i32 %23, i32* %8
%24 = load i8, i8* %7
%25 = zext i8 %24 to i32
%26 = icmp eq i32 %25, 10
br i1 %26, label %27, label %28
27: ; preds = %17
br label %31
28: ; preds = %17
br label %30
29: ; preds = %13
br label %31
30: ; preds = %28
br label %9
31: ; preds = %29, %27, %9
%32 = load i32, i32* %8
ret i32 %32
}

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