#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 /*<<< orphan*/ ConsoleWrite(char *);
char GetKeypress();
int GetLine(char *String) {
  int i;
  char Character[2];
  Character[1] = '\0';
  i = 0;
  do {
    Character[0] = GetKeypress();
    if (Character[0] != '\0') {
      ConsoleWrite(Character);
      String[i] = Character[0];
      i++;
    }
  } while (Character[0] != '\n');
  String[i] = '\0';
  return i;
}


x86 assembly (clang, -O0):
<GetLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0xd(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <GetKeypress@plt>
mov    %al,-0xe(%rbp)
movsbl -0xe(%rbp),%eax
cmp    $0x0,%eax
je     116e <GetLine+0x4e>
lea    -0xe(%rbp),%rdi
call   1030 <ConsoleWrite@plt>
mov    -0xe(%rbp),%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    1173 <GetLine+0x53>
movsbl -0xe(%rbp),%eax
cmp    $0xa,%eax
jne    1137 <GetLine+0x17>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetLine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
movb   $0x0,0x7(%rsp)
xor    %ebx,%ebx
lea    0x6(%rsp),%r14
jmp    1146 <GetLine+0x26>
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%bpl
je     1170 <GetLine+0x50>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <GetKeypress@plt>
mov    %al,0x6(%rsp)
test   %al,%al
je     1140 <GetLine+0x20>
mov    %r14,%rdi
call   1030 <ConsoleWrite@plt>
movzbl 0x6(%rsp),%ebp
movslq %ebx,%rbx
mov    %bpl,(%r15,%rbx,1)
add    $0x1,%ebx
jmp    1140 <GetLine+0x20>
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @GetLine(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [2 x i8]
store i8* %0, i8** %2
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 0, i8* %5
store i32 0, i32* %3
br label %6
6: ; preds = %25, %1
%7 = call signext i8 (...) @GetKeypress()
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
store i8 %7, i8* %8
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %6
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%15 = call i32 @ConsoleWrite(i8* %14)
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%17 = load i8, i8* %16
%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
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %24
24: ; preds = %13, %6
br label %25
25: ; preds = %24
%26 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 10
br i1 %29, label %6, label %30
30: ; preds = %25
%31 = load i8*, i8** %2
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
define i32 @GetLine(i8* nocapture writeonly %0) {
%2 = alloca [2 x i8]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
store i8 0, i8* %4
br label %5
5: ; preds = %15, %1
%6 = phi i32 [ 0, %1 ], [ %17, %15 ]
%7 = call signext i8 (...) @GetKeypress()
store i8 %7, i8* %3
%8 = icmp eq i8 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %5
%10 = call i32 @ConsoleWrite(i8* %3)
%11 = load i8, i8* %3
%12 = sext i32 %6 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 %11, i8* %13
%14 = add nsw i32 %6, 1
br label %15
15: ; preds = %5, %9
%16 = phi i8 [ 0, %5 ], [ %11, %9 ]
%17 = phi i32 [ %6, %5 ], [ %14, %9 ]
%18 = icmp eq i8 %16, 10
br i1 %18, label %19, label %5
19: ; preds = %15
%20 = sext i32 %17 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
store i8 0, i8* %21
ret i32 %17
}