#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 */

/* Variables and functions */
int /*<<< orphan*/ memset(char *, char, int);
int read(int, char *, int);
int get_line(int handle, char *buf) {
  int offset = 0;
  memset(buf, '\0', 256);
  while (1) {
    int r = read(handle, buf + offset, 1);
    if (r == -1 || r == 0)
      break;
    if (buf[offset] == '\n')
      break;
    else {
      if (offset >= 255)
        break;
      else
        offset += 1;
    }
  }
  return offset;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1030 <memset@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
je     1175 <get_line+0x55>
cmpl   $0x0,-0x18(%rbp)
jne    117a <get_line+0x5a>
jmp    11b9 <get_line+0x99>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1194 <get_line+0x74>
jmp    11b9 <get_line+0x99>
cmpl   $0xff,-0x14(%rbp)
jl     11a6 <get_line+0x86>
jmp    11b9 <get_line+0x99>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b4 <get_line+0x94>
jmp    1146 <get_line+0x26>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
xor    %ebx,%ebx
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1030 <memset@plt>
xchg   %ax,%ax
mov    %rbx,%rbp
add    %r15,%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
add    $0x1,%eax
cmp    $0x2,%eax
jb     1170 <get_line+0x50>
cmpb   $0xa,(%rbx)
je     1170 <get_line+0x50>
lea    0x1(%rbp),%rbx
cmp    $0xff,%rbp
jb     1140 <get_line+0x20>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_line(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
%7 = load i8*, i8** %4
%8 = call i32 @memset(i8* %7, i8 signext 0, i32 256)
br label %9
9: ; preds = %2, %39
%10 = load i32, i32* %3
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = call i32 @read(i32 %10, i8* %14, i32 1)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, -1
br i1 %17, label %21, label %18
18: ; preds = %9
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18, %9
br label %40
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 10
br i1 %29, label %30, label %31
30: ; preds = %22
br label %40
31: ; preds = %22
%32 = load i32, i32* %5
%33 = icmp sge i32 %32, 255
br i1 %33, label %34, label %35
34: ; preds = %31
br label %40
35: ; preds = %31
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %38
38: ; preds = %35
br label %39
39: ; preds = %38
br label %9
40: ; preds = %34, %30, %21
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
define i32 @get_line(i32 %0, i8* %1) {
%3 = tail call i32 @memset(i8* %1, i8 signext 0, i32 256)
br label %4
4: ; preds = %10, %2
%5 = phi i64 [ %15, %10 ], [ 0, %2 ]
%6 = getelementptr inbounds i8, i8* %1, i64 %5
%7 = tail call i32 @read(i32 %0, i8* %6, i32 1)
%8 = add i32 %7, 1
%9 = icmp ult i32 %8, 2
br i1 %9, label %16, label %10
10: ; preds = %4
%11 = load i8, i8* %6
%12 = icmp eq i8 %11, 10
%13 = icmp ugt i64 %5, 254
%14 = select i1 %12, i1 true, i1 %13
%15 = add nuw nsw i64 %5, 1
br i1 %14, label %16, label %4
16: ; preds = %10, %4
%17 = trunc i64 %5 to i32
ret i32 %17
}