#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 */
char getch();
int /*<<< orphan*/ printf(char *);
char *PlatformGetLine(char *Buf, int MaxLen) {
  int ix;
  char ch, *cp;
  ix = 0;
  cp = Buf;
  while (ix++ < MaxLen) {
    ch = getch();
    if (ch == 0x1B) {
      printf("leaving picoC\n\r");
      return 0;
    }
    if (ch == '\n') {
      *cp++ = '\n';
      *cp = 0;
      return Buf;
    }
    *cp++ = ch;
    ix++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<PlatformGetLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
cmp    -0x14(%rbp),%eax
jge    11d7 <PlatformGetLine+0xb7>
mov    $0x0,%al
call   1040 <getch@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x1b,%eax
jne    1182 <PlatformGetLine+0x62>
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11df <PlatformGetLine+0xbf>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    11b5 <PlatformGetLine+0x95>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0xa,(%rax)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <PlatformGetLine+0xbf>
mov    -0x19(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113e <PlatformGetLine+0x1e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PlatformGetLine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    1172 <PlatformGetLine+0x52>
mov    %esi,%r15d
mov    %rdi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getch@plt>
cmp    $0xa,%al
je     115f <PlatformGetLine+0x3f>
cmp    $0x1b,%al
je     1166 <PlatformGetLine+0x46>
mov    %al,(%rbx)
add    $0x1,%rbx
add    $0x2,%ebp
cmp    %r15d,%ebp
jl     1140 <PlatformGetLine+0x20>
jmp    1172 <PlatformGetLine+0x52>
movw   $0xa,(%rbx)
jmp    1175 <PlatformGetLine+0x55>
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"leaving picoC\0A\0D\00"
define i8* @PlatformGetLine(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
%9 = load i8*, i8** %4
store i8* %9, i8** %8
br label %10
10: ; preds = %31, %2
%11 = load i32, i32* %6
%12 = add nsw i32 %11, 1
store i32 %12, i32* %6
%13 = load i32, i32* %5
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %37
15: ; preds = %10
%16 = call signext i8 (...) @getch()
store i8 %16, i8* %7
%17 = load i8, i8* %7
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 27
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %38
22: ; preds = %15
%23 = load i8, i8* %7
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i8*, i8** %8
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %8
store i8 10, i8* %27
%29 = load i8*, i8** %8
store i8 0, i8* %29
%30 = load i8*, i8** %4
store i8* %30, i8** %3
br label %38
31: ; preds = %22
%32 = load i8, i8* %7
%33 = load i8*, i8** %8
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %8
store i8 %32, i8* %33
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %10
37: ; preds = %10
store i8* null, i8** %3
br label %38
38: ; preds = %37, %26, %20
%39 = load i8*, i8** %3
ret i8* %39
}

LLVM IR (-O2):
@.str = [16 x i8] c"leaving picoC\0A\0D\00"
define i8* @PlatformGetLine(i8* writeonly %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %16
4: ; preds = %2, %12
%5 = phi i8* [ %13, %12 ], [ %0, %2 ]
%6 = phi i32 [ %14, %12 ], [ 0, %2 ]
%7 = tail call signext i8 (...) @getch()
switch i8 %7, label %12 [
i8 27, label %8
i8 10, label %10
]
8: ; preds = %4
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %16
10: ; preds = %4
%11 = getelementptr inbounds i8, i8* %5, i64 1
store i8 10, i8* %5
store i8 0, i8* %11
br label %16
12: ; preds = %4
%13 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %7, i8* %5
%14 = add nuw nsw i32 %6, 2
%15 = icmp slt i32 %14, %1
br i1 %15, label %4, label %16
16: ; preds = %12, %2, %10, %8
%17 = phi i8* [ null, %8 ], [ %0, %10 ], [ null, %2 ], [ null, %12 ]
ret i8* %17
}