#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();
int /*<<< orphan*/ printf(char *);
void getline_my(char line[]) {
  int i = 0;
  int c = 0;
  printf("Please input line:\n");
  for (i = 0; ((c = getchar()) != EOF) && c != '\n'; ++i) {
    line[i] = c;
  };
}


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)
lea    0xebf(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
xor    %eax,%eax
mov    0x2e86(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x11(%rbp)
je     1177 <getline_my+0x57>
cmpl   $0xa,-0x10(%rbp)
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1187 <getline_my+0x67>
jmp    11a5 <getline_my+0x85>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114d <getline_my+0x2d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getline_my>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xed2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     1167 <getline_my+0x47>
mov    0x2ea2(%rip),%r14
cmp    (%r14),%eax
je     1167 <getline_my+0x47>
nopl   0x0(%rax,%rax,1)
mov    %al,(%rbx)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     1167 <getline_my+0x47>
add    $0x1,%rbx
cmp    (%r14),%eax
jne    1150 <getline_my+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@EOF = global i32 0
@str = [19 x i8] c"Please input line:\00"
define void @getline_my(i8* nocapture writeonly %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (...) @getchar()
%4 = load i32, i32* @EOF
%5 = icmp ne i32 %3, %4
%6 = icmp ne i32 %3, 10
%7 = and i1 %6, %5
br i1 %7, label %8, label %19
8: ; preds = %1, %8
%9 = phi i64 [ %13, %8 ], [ 0, %1 ]
%10 = phi i32 [ %14, %8 ], [ %3, %1 ]
%11 = trunc i32 %10 to i8
%12 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %11, i8* %12
%13 = add nuw i64 %9, 1
%14 = tail call i32 (...) @getchar()
%15 = load i32, i32* @EOF
%16 = icmp ne i32 %14, %15
%17 = icmp ne i32 %14, 10
%18 = and i1 %17, %16
br i1 %18, label %8, label %19
19: ; preds = %8, %1
ret void
}