#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 getch();
int getline_my(char *string) {
  int i = 0;
  char exit = 0;
  char c = 0;
  c = getch();
  exit = 0;
  while (exit == 0) {
    if (c == EOF || c == '\n') {
      exit = 1;
      *string++;
      *string = '\0';
    } else {
      *string++ = c;
      c = getch();
      i++;
    };
  };
  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)
movb   $0x0,-0xe(%rbp)
mov    $0x0,%al
call   1030 <getch@plt>
mov    %al,-0xe(%rbp)
movb   $0x0,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0x0,%eax
jne    11b1 <getline_my+0xa1>
movsbl -0xe(%rbp),%eax
mov    0x2e97(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1169 <getline_my+0x59>
movsbl -0xe(%rbp),%eax
cmp    $0xa,%eax
jne    1185 <getline_my+0x75>
movb   $0x1,-0xd(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    11ac <getline_my+0x9c>
mov    -0xe(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    $0x0,%al
call   1030 <getch@plt>
mov    %al,-0xe(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1139 <getline_my+0x29>
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 <getch@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 <getch@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,0x1(%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
%5 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
store i8 0, i8* %4
store i8 0, i8* %5
%6 = call signext i8 (...) @getch()
store i8 %6, i8* %5
store i8 0, i8* %4
br label %7
7: ; preds = %33, %1
%8 = load i8, i8* %4
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %34
11: ; preds = %7
%12 = load i8, i8* %5
%13 = sext i8 %12 to i32
%14 = load i8, i8* @EOF
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %13, %15
br i1 %16, label %21, label %17
17: ; preds = %11
%18 = load i8, i8* %5
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %26
21: ; preds = %17, %11
store i8 1, i8* %4
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %2
%24 = load i8, i8* %22
%25 = load i8*, i8** %2
store i8 0, i8* %25
br label %33
26: ; preds = %17
%27 = load i8, i8* %5
%28 = load i8*, i8** %2
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %2
store i8 %27, i8* %28
%30 = call signext i8 (...) @getch()
store i8 %30, i8* %5
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %33
33: ; preds = %26, %21
br label %7
34: ; preds = %7
%35 = load i32, i32* %3
ret i32 %35
}

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