#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, char, char *);
void getline_my(char *line) {
  int i = 0;
  int c = 0;
  for (i = 0; ((c = getchar()) != EOF) && c != '\n' && i < 100; line++, i++) {
    *line = c;
    printf("line [ %d ] = %c; line = %p;\n", i, *line, line);
  };
  *line++ = '\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   $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     117a <getline_my+0x5a>
xor    %eax,%eax
cmpl   $0xa,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     117a <getline_my+0x5a>
cmpl   $0x64,-0xc(%rbp)
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    118a <getline_my+0x6a>
jmp    11cb <getline_my+0xab>
mov    -0x10(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rcx
lea    0xe57(%rip),%rdi
movsbl %al,%edx
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1141 <getline_my+0x21>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getline_my>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     1184 <getline_my+0x64>
mov    0x2eaa(%rip),%r15
cmp    (%r15),%eax
je     1184 <getline_my+0x64>
lea    0xeb6(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
lea    (%r12,%rbx,1),%rcx
mov    %al,(%r12,%rbx,1)
mov    %ebx,%ebp
movsbl %al,%edx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
add    $0x1,%rbx
cmp    $0xa,%eax
je     1181 <getline_my+0x61>
cmp    (%r15),%eax
je     1181 <getline_my+0x61>
cmp    $0x63,%ebp
jb     1150 <getline_my+0x30>
add    %rbx,%r12
movb   $0x0,(%r12)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
@.str = [30 x i8] c"line [ %d ] = %c; line = %p;\0A\00"
define void @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 %22
7: ; preds = %1, %7
%8 = phi i32 [ %15, %7 ], [ %2, %1 ]
%9 = phi i32 [ %14, %7 ], [ 0, %1 ]
%10 = phi i8* [ %13, %7 ], [ %0, %1 ]
%11 = trunc i32 %8 to i8
store i8 %11, i8* %10
%12 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %9, i8 signext %11, i8* %10)
%13 = getelementptr inbounds i8, i8* %10, i64 1
%14 = add nuw nsw i32 %9, 1
%15 = tail call i32 (...) @getchar()
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %15, %16
%18 = icmp ne i32 %15, 10
%19 = and i1 %18, %17
%20 = icmp ult i32 %9, 99
%21 = and i1 %19, %20
br i1 %21, label %7, label %22
22: ; preds = %7, %1
%23 = phi i8* [ %0, %1 ], [ %13, %7 ]
store i8 0, i8* %23
ret void
}