#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 gettext_my(char text[100]) {
  int i = 0;
  int c = 0;
  while ((c = getchar()) != EOF) {
    text[i] = c;
    ++i;
  };
  ++i;
  text[i] = EOF;
}


x86 assembly (clang, -O0):
<gettext_my>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,-0x10(%rbp)
mov    0x2ead(%rip),%rcx
cmp    (%rcx),%eax
je     1161 <gettext_my+0x51>
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    112a <gettext_my+0x1a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettext_my>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %eax,%eax
call   1030 <getchar@plt>
mov    0x2ec2(%rip),%r14
mov    $0x1,%ecx
cmp    (%r14),%eax
je     1157 <gettext_my+0x47>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %al,-0x1(%r15,%rbx,1)
xor    %eax,%eax
call   1030 <getchar@plt>
add    $0x1,%rbx
cmp    (%r14),%eax
jne    1140 <gettext_my+0x30>
mov    %ebx,%ecx
mov    %al,(%r15,%rcx,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
define void @gettext_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
br label %5
5: ; preds = %9, %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 %18
9: ; preds = %5
%10 = load i32, i32* %4
%11 = trunc i32 %10 to i8
%12 = load i8*, i8** %2
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
store i8 %11, i8* %15
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %5
18: ; preds = %5
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
%21 = load i32, i32* @EOF
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %2
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 %22, i8* %26
ret void
}

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