#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 *, char *);
int main(int argc, char *argv[]) {
  char ch, buffer[80 + 1];
  int x = 0;
  while ((ch = getchar()) != '\n' && x < 80)
    buffer[x++] = ch;
  buffer[x] = '\0';
  printf("%s\n", buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x74(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x75(%rbp)
je     1165 <main+0x45>
cmpl   $0x50,-0x74(%rbp)
setl   %al
mov    %al,-0x75(%rbp)
mov    -0x75(%rbp),%al
test   $0x1,%al
jne    1175 <main+0x55>
jmp    118e <main+0x6e>
mov    -0x11(%rbp),%cl
mov    -0x74(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x74(%rbp)
cltq
mov    %cl,-0x70(%rbp,%rax,1)
jmp    1140 <main+0x20>
movslq -0x74(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rsi
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
je     115b <main+0x3b>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbx),%r14
mov    %al,(%rsp,%rbx,1)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
je     115b <main+0x3b>
cmp    $0x4f,%rbx
mov    %r14,%rbx
jb     1140 <main+0x20>
movb   $0x0,(%rsp,%r14,1)
lea    0xe99(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [81 x i8]
%4 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%5 = tail call signext i8 (...) @getchar()
%6 = icmp eq i8 %5, 10
br i1 %6, label %16, label %7
7: ; preds = %2, %7
%8 = phi i64 [ %10, %7 ], [ 0, %2 ]
%9 = phi i8 [ %12, %7 ], [ %5, %2 ]
%10 = add nuw nsw i64 %8, 1
%11 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 %8
store i8 %9, i8* %11
%12 = tail call signext i8 (...) @getchar()
%13 = icmp ne i8 %12, 10
%14 = icmp ult i64 %8, 79
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %7, label %16
16: ; preds = %7, %2
%17 = phi i64 [ 0, %2 ], [ %10, %7 ]
%18 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
ret i32 0
}