#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 EOF;
int fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
void getLine(char *ptr) {
  int c;
  int len = 30;
  for (;;) {
    c = fgetc(stdin);
    if (c == EOF)
      break;
    if (--len == 0)
      break;
    *ptr = c;
    if (c == '\n')
      break;
    ptr++;
  }
  *ptr = 0;
}


x86 assembly (clang, -O0):
<getLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1e,-0x10(%rbp)
mov    0x2ebe(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2ea2(%rip),%rcx
cmp    (%rcx),%eax
jne    114b <getLine+0x3b>
jmp    118d <getLine+0x7d>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jne    1162 <getLine+0x52>
jmp    118d <getLine+0x7d>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
cmpl   $0xa,-0xc(%rbp)
jne    117c <getLine+0x6c>
jmp    118d <getLine+0x7d>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1123 <getLine+0x13>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLine>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r12
mov    0x2ec5(%rip),%r14
mov    (%r14),%edi
call   1030 <fgetc@plt>
mov    0x2eae(%rip),%r15
cmp    (%r15),%eax
je     116b <getLine+0x5b>
xor    %ebx,%ebx
mov    %r12,%r13
nopl   0x0(%rax)
cmp    $0x1d,%ebx
je     1163 <getLine+0x53>
mov    %al,(%r12,%rbx,1)
cmp    $0xa,%eax
je     1168 <getLine+0x58>
add    $0x1,%r13
mov    (%r14),%edi
call   1030 <fgetc@plt>
add    $0x1,%rbx
cmp    (%r15),%eax
jne    1140 <getLine+0x30>
add    %rbx,%r12
jmp    116b <getLine+0x5b>
mov    %r13,%r12
movb   $0x0,(%r12)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
define void @getLine(i8* nocapture writeonly %0) {
%2 = load i32, i32* @stdin
%3 = tail call i32 @fgetc(i32 %2)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %21, label %6
6: ; preds = %1, %15
%7 = phi i32 [ %18, %15 ], [ %3, %1 ]
%8 = phi i32 [ %10, %15 ], [ 30, %1 ]
%9 = phi i8* [ %16, %15 ], [ %0, %1 ]
%10 = add nsw i32 %8, -1
%11 = icmp eq i32 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %6
%13 = trunc i32 %7 to i8
store i8 %13, i8* %9
%14 = icmp eq i32 %7, 10
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %9, i64 1
%17 = load i32, i32* @stdin
%18 = tail call i32 @fgetc(i32 %17)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %6
21: ; preds = %15, %6, %12, %1
%22 = phi i8* [ %0, %1 ], [ %9, %12 ], [ %9, %6 ], [ %16, %15 ]
store i8 0, i8* %22
ret void
}