#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 *, ...);
int getline_my(char line[]) {
  int i = 0;
  int c = 0;
  for (i = 0; ((c = getchar()) != EOF) && c != '\n'; ++i) {
    line[i] = c;
    printf("line[%d] = %c; i = %d;\n", i, line[i], i);
  }
  line[++i] = '\0';
  printf("getted string:%s;\n", line);
  return i;
}


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   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
xor    %eax,%eax
mov    0x2e92(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x11(%rbp)
je     116b <getline_my+0x4b>
cmpl   $0xa,-0x10(%rbp)
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    117b <getline_my+0x5b>
jmp    11b9 <getline_my+0x99>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
mov    -0xc(%rbp),%ecx
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1141 <getline_my+0x21>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getline_my>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <getchar@plt>
mov    $0x1,%ebx
cmp    $0xa,%eax
je     118e <getline_my+0x6e>
mov    0x2ea5(%rip),%r12
cmp    (%r12),%eax
je     118e <getline_my+0x6e>
lea    0xeb0(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %al,(%r14,%rbx,1)
movsbl %al,%edx
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     118b <getline_my+0x6b>
cmp    (%r12),%eax
jne    1160 <getline_my+0x40>
add    $0x1,%ebx
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
lea    0xe7c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [24 x i8] c"line[%d] = %c; i = %d;\0A\00"
@.str.1 = [19 x i8] c"getted string:%s;\0A\00"
define i32 @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
store i32 0, i32* %3
br label %5
5: ; preds = %30, %1
%6 = call i32 (...) @getchar()
store i32 %6, i32* %4
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 10
br label %12
12: ; preds = %9, %5
%13 = phi i1 [ false, %5 ], [ %11, %9 ]
br i1 %13, label %14, label %33
14: ; preds = %12
%15 = load i32, i32* %4
%16 = trunc i32 %15 to i8
%17 = load i8*, i8** %2
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8 %16, i8* %20
%21 = load i32, i32* %3
%22 = load i8*, i8** %2
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = load i32, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %27, i32 %28)
br label %30
30: ; preds = %14
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %5
33: ; preds = %12
%34 = load i8*, i8** %2
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %2
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %39)
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [24 x i8] c"line[%d] = %c; i = %d;\0A\00"
@.str.1 = [19 x i8] c"getted string:%s;\0A\00"
define i32 @getline_my(i8* %0) {
%2 = tail call i32 (...) @getchar()
%3 = load i32, i32* @EOF
%4 = icmp ne i32 %2, %3
%5 = icmp ne i32 %2, 10
%6 = and i1 %5, %4
br i1 %6, label %7, label %25
7: ; preds = %1, %7
%8 = phi i64 [ %16, %7 ], [ 0, %1 ]
%9 = phi i32 [ %17, %7 ], [ %2, %1 ]
%10 = trunc i32 %9 to i8
%11 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %10, i8* %11
%12 = shl i32 %9, 24
%13 = ashr exact i32 %12, 24
%14 = trunc i64 %8 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %13, i32 %14)
%16 = add nuw i64 %8, 1
%17 = tail call i32 (...) @getchar()
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
%20 = icmp ne i32 %17, 10
%21 = and i1 %20, %19
br i1 %21, label %7, label %22
22: ; preds = %7
%23 = trunc i64 %16 to i32
%24 = add i32 %23, 1
br label %25
25: ; preds = %22, %1
%26 = phi i32 [ 1, %1 ], [ %24, %22 ]
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %0, i64 %27
store i8 0, i8* %28
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0)
ret i32 %26
}