#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 getchar();
void getline_my(char s[10000]) {
  int c = 0;
  int i = 0;
  int lim = 10000;
  while ((--lim > 0) && ((c = getchar()) != EOF) && c != '\n')
    s[i++] = c;
  if (c == '\n') {
    s[i++] = '\n';
  };
  s[i] = '\0';
}


x86 assembly (clang, -O0):
<getline_my>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x2710,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
jle    1172 <getline_my+0x62>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2e8b(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x15(%rbp)
je     1172 <getline_my+0x62>
cmpl   $0xa,-0xc(%rbp)
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1182 <getline_my+0x72>
jmp    11a1 <getline_my+0x91>
mov    -0xc(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1131 <getline_my+0x21>
cmpl   $0xa,-0xc(%rbp)
jne    11c1 <getline_my+0xb1>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
movslq %ecx,%rcx
movb   $0xa,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getline_my>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2ec9(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%eax
je     1159 <getline_my+0x49>
cmp    (%r15),%eax
je     1159 <getline_my+0x49>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    $0x270f,%rbx
jne    1130 <getline_my+0x20>
mov    $0x270f,%ebx
jmp    1167 <getline_my+0x57>
cmp    $0xa,%eax
jne    1167 <getline_my+0x57>
movb   $0xa,(%r14,%rbx,1)
add    $0x1,%rbx
movslq %ebx,%rax
movb   $0x0,(%r14,%rax,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
define void @getline_my(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 10000, i32* %5
br label %6
6: ; preds = %19, %1
%7 = load i32, i32* %5
%8 = add nsw i32 %7, -1
store i32 %8, i32* %5
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = call i32 (...) @getchar()
store i32 %11, i32* %3
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* %3
%16 = icmp ne i32 %15, 10
br label %17
17: ; preds = %14, %10, %6
%18 = phi i1 [ false, %10 ], [ false, %6 ], [ %16, %14 ]
br i1 %18, label %19, label %27
19: ; preds = %17
%20 = load i32, i32* %3
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %2
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 %21, i8* %26
br label %6
27: ; preds = %17
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 10
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i8*, i8** %2
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 10, i8* %35
br label %36
36: ; preds = %30, %27
%37 = load i8*, i8** %2
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 0, i8* %40
ret void
}

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