#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 */
char EOF;
char getchar();
int getline_my(char *line) {
  int i = 0;
  char c = 0;
  while ((c = getchar()) != EOF && c != '\n') {
    *line++ = c;
    i++;
  };
  *line = '\0';
  return i;
}


x86 assembly (clang, -O0):
<getline_my>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0xd(%rbp)
movsbl %al,%ecx
mov    0x2ead(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0xe(%rbp)
je     1158 <getline_my+0x48>
movsbl -0xd(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
test   $0x1,%al
jne    1168 <getline_my+0x58>
jmp    118a <getline_my+0x7a>
mov    -0xd(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1127 <getline_my+0x17>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getline_my>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     115b <getline_my+0x4b>
mov    0x2ebc(%rip),%r15
cmp    (%r15),%al
je     115b <getline_my+0x4b>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %al,(%r14,%rbx,1)
xor    %eax,%eax
call   1030 <getchar@plt>
add    $0x1,%rbx
cmp    $0xa,%al
je     1158 <getline_my+0x48>
cmp    (%r15),%al
jne    1140 <getline_my+0x30>
add    %rbx,%r14
movb   $0x0,(%r14)
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i8 0
define i32 @getline_my(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
store i8 0, i8* %4
br label %5
5: ; preds = %17, %1
%6 = call signext i8 (...) @getchar()
store i8 %6, i8* %4
%7 = sext i8 %6 to i32
%8 = load i8, i8* @EOF
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %7, %9
br i1 %10, label %11, label %15
11: ; preds = %5
%12 = load i8, i8* %4
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 10
br label %15
15: ; preds = %11, %5
%16 = phi i1 [ false, %5 ], [ %14, %11 ]
br i1 %16, label %17, label %23
17: ; preds = %15
%18 = load i8, i8* %4
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %2
store i8 %18, i8* %19
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %5
23: ; preds = %15
%24 = load i8*, i8** %2
store i8 0, i8* %24
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@EOF = global i8 0
define i32 @getline_my(i8* nocapture writeonly %0) {
%2 = tail call signext i8 (...) @getchar()
%3 = load i8, i8* @EOF
%4 = icmp ne i8 %2, %3
%5 = icmp ne i8 %2, 10
%6 = and i1 %5, %4
br i1 %6, label %7, label %18
7: ; preds = %1, %7
%8 = phi i8 [ %13, %7 ], [ %2, %1 ]
%9 = phi i32 [ %12, %7 ], [ 0, %1 ]
%10 = phi i8* [ %11, %7 ], [ %0, %1 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %8, i8* %10
%12 = add nuw nsw i32 %9, 1
%13 = tail call signext i8 (...) @getchar()
%14 = load i8, i8* @EOF
%15 = icmp ne i8 %13, %14
%16 = icmp ne i8 %13, 10
%17 = and i1 %16, %15
br i1 %17, label %7, label %18
18: ; preds = %7, %1
%19 = phi i8* [ %0, %1 ], [ %11, %7 ]
%20 = phi i32 [ 0, %1 ], [ %12, %7 ]
store i8 0, i8* %19
ret i32 %20
}