#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 getchar();
int /*<<< orphan*/ printf(char *);
void getLongString(char longString[]) {
  char ch;
  int i = 0;
  printf("Enter long string, spaces are ok: ");
  while (ch != '\n') {
    ch = getchar();
    longString[i] = ch;
    i++;
  }
  longString[i] = '\0';
  return;
}


x86 assembly (clang, -O0):
<getLongString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xec6(%rip),%rdi
call   1030 <printf@plt>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
je     1172 <getLongString+0x52>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%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    113f <getLongString+0x1f>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLongString>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xed2(%rip),%rdi
call   1030 <printf@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    $0xa,%al
jne    1140 <getLongString+0x20>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Enter long string, spaces are ok: \00"
define void @getLongString(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
%5 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %10, %1
%7 = load i8, i8* %3
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 10
br i1 %9, label %10, label %19
10: ; preds = %6
%11 = call signext i8 (...) @getchar()
store i8 %11, i8* %3
%12 = load i8, i8* %3
%13 = load i8*, i8** %2
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
store i8 %12, i8* %16
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %6
19: ; preds = %6
%20 = load i8*, i8** %2
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 0, i8* %23
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"Enter long string, spaces are ok: \00"
define void @getLongString(i8* nocapture writeonly %0) {
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %1, %3
%4 = phi i64 [ 0, %1 ], [ %7, %3 ]
%5 = tail call signext i8 (...) @getchar()
%6 = getelementptr inbounds i8, i8* %0, i64 %4
store i8 %5, i8* %6
%7 = add nuw i64 %4, 1
%8 = icmp eq i8 %5, 10
br i1 %8, label %9, label %3
9: ; preds = %3
%10 = and i64 %7, 4294967295
%11 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 0, i8* %11
ret void
}