#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(char line[], int limit) {
  int size, c;
  printf("Please enter a phrase or return to end this\n");
  for (size = 0; size < limit - 1 && (c = getchar()) != EOF && c != '\n';
       size++)
    line[size] = c;
  line[size] = '\0';
  return size;
}


x86 assembly (clang, -O0):
<getLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x15(%rbp)
jge    1182 <getLine+0x62>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
mov    0x2e7b(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x15(%rbp)
je     1182 <getLine+0x62>
cmpl   $0xa,-0x14(%rbp)
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1192 <getLine+0x72>
jmp    11b0 <getLine+0x90>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1142 <getLine+0x22>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLine>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0xecb(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
cmp    $0x2,%r14d
jl     1182 <getLine+0x62>
add    $0xffffffff,%r14d
mov    %r14d,%ebx
mov    0x2e98(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     1182 <getLine+0x62>
cmp    (%r12),%eax
je     1182 <getLine+0x62>
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <getLine+0x40>
mov    %r14d,%ebp
mov    %ebp,%eax
movb   $0x0,(%r15,%rax,1)
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"Please enter a phrase or return to end this\0A\00"
@EOF = global i32 0
define i32 @getLine(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %8
8: ; preds = %29, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %20
13: ; preds = %8
%14 = call i32 (...) @getchar()
store i32 %14, i32* %6
%15 = load i32, i32* @EOF
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 10
br label %20
20: ; preds = %17, %13, %8
%21 = phi i1 [ false, %13 ], [ false, %8 ], [ %19, %17 ]
br i1 %21, label %22, label %32
22: ; preds = %20
%23 = load i32, i32* %6
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %3
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 %24, i8* %28
br label %29
29: ; preds = %22
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %8
32: ; preds = %20
%33 = load i8*, i8** %3
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 0, i8* %36
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
@EOF = global i32 0
@str = [44 x i8] c"Please enter a phrase or return to end this\00"
define i32 @getLine(i8* nocapture writeonly %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%4 = add i32 %1, -1
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %22
6: ; preds = %2
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %15
%9 = phi i64 [ 0, %6 ], [ %18, %15 ]
%10 = tail call i32 (...) @getchar()
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %10, %11
%13 = icmp ne i32 %10, 10
%14 = and i1 %13, %12
br i1 %14, label %15, label %20
15: ; preds = %8
%16 = trunc i32 %10 to i8
%17 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %16, i8* %17
%18 = add nuw nsw i64 %9, 1
%19 = icmp eq i64 %18, %7
br i1 %19, label %22, label %8
20: ; preds = %8
%21 = trunc i64 %9 to i32
br label %22
22: ; preds = %15, %20, %2
%23 = phi i32 [ 0, %2 ], [ %21, %20 ], [ %4, %15 ]
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %0, i64 %24
store i8 0, i8* %25
ret i32 %23
}