#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 getchar();
int /*<<< orphan*/ printf(char *);
int getLine(char line[]) {
  int c;
  int size = 0;
  printf("Please enter a phrase\n");
  while (size < 50 && (c = getchar()) != '\n') {
    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)
movl   $0x0,-0x10(%rbp)
lea    0xec6(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
cmpl   $0x32,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jge    1161 <getLine+0x41>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xa,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1171 <getLine+0x51>
jmp    1190 <getLine+0x70>
mov    -0xc(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    113f <getLine+0x1f>
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   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xed2(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     115f <getLine+0x3f>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    $0x32,%rbx
jne    1140 <getLine+0x20>
mov    $0x32,%ebx
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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