#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 getc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
void read_line(void) {
  const int buf_sz = 1024;
  char buf[buf_sz + 1];
  int c, i = 0;
  while ((i < buf_sz) && ((c = getc(stdin)) != EOF)) {
    if (c == '\n' || (i == buf_sz - 1)) {
      buf[i] = 0;
      break;
    }
    buf[i] = c;
    ++i;
  }
  printf("input: %s", buf);
}


x86 assembly (clang, -O0):
<read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x400,-0x4(%rbp)
mov    %rsp,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x400,-0x18(%rbp)
mov    %al,-0x421(%rbp)
jge    1178 <read_line+0x58>
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
call   1040 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x421(%rbp)
mov    -0x421(%rbp),%al
test   $0x1,%al
jne    118b <read_line+0x6b>
jmp    11d1 <read_line+0xb1>
cmpl   $0xa,-0x14(%rbp)
je     11a2 <read_line+0x82>
cmpl   $0x3ff,-0x18(%rbp)
jne    11b3 <read_line+0x93>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
jmp    11d1 <read_line+0xb1>
mov    -0x14(%rbp),%eax
mov    %al,%cl
movslq -0x18(%rbp),%rax
mov    %cl,-0x420(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1140 <read_line+0x20>
lea    0xe28(%rip),%rdi
lea    -0x420(%rbp),%rsi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_line>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    0x2eb5(%rip),%r14
mov    (%r14),%edi
call   1040 <getc@plt>
mov    0x2e9e(%rip),%r15
cmp    (%r15),%eax
je     1178 <read_line+0x58>
xor    %ebx,%ebx
nopl   0x0(%rax)
cmp    $0xa,%eax
je     1174 <read_line+0x54>
cmp    $0x3ff,%rbx
je     1174 <read_line+0x54>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
mov    (%r14),%edi
call   1040 <getc@plt>
cmp    (%r15),%eax
jne    1150 <read_line+0x30>
jmp    1178 <read_line+0x58>
movb   $0x0,(%rsp,%rbx,1)
lea    0xe81(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i32 0
@.str = [10 x i8] c"input: %s\00"
define void @read_line() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 1024, i32* %1
%5 = call i8* @llvm.stacksave()
store i8* %5, i8** %2
%6 = alloca i8, i64 1025
store i32 0, i32* %4
br label %7
7: ; preds = %27, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 1024
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = load i32, i32* @stdin
%12 = call i32 @getc(i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br label %15
15: ; preds = %10, %7
%16 = phi i1 [ false, %7 ], [ %14, %10 ]
br i1 %16, label %17, label %35
17: ; preds = %15
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 10
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 1023
br i1 %22, label %23, label %27
23: ; preds = %20, %17
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %6, i64 %25
store i8 0, i8* %26
br label %35
27: ; preds = %20
%28 = load i32, i32* %3
%29 = trunc i32 %28 to i8
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %6, i64 %31
store i8 %29, i8* %32
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %7
35: ; preds = %23, %15
%36 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %6)
%37 = load i8*, i8** %2
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
@.str = [10 x i8] c"input: %s\00"
define void @read_line() {
%1 = alloca [1025 x i8]
%2 = load i32, i32* @stdin
%3 = tail call i32 @getc(i32 %2)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %23, label %6
6: ; preds = %0, %15
%7 = phi i64 [ %18, %15 ], [ 0, %0 ]
%8 = phi i32 [ %20, %15 ], [ %3, %0 ]
%9 = icmp eq i32 %8, 10
%10 = icmp eq i64 %7, 1023
%11 = select i1 %9, i1 true, i1 %10
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = and i64 %7, 4294967295
%14 = getelementptr inbounds [1025 x i8], [1025 x i8]* %1, i64 0, i64 %13
store i8 0, i8* %14
br label %23
15: ; preds = %6
%16 = trunc i32 %8 to i8
%17 = getelementptr inbounds [1025 x i8], [1025 x i8]* %1, i64 0, i64 %7
store i8 %16, i8* %17
%18 = add nuw nsw i64 %7, 1
%19 = load i32, i32* @stdin
%20 = tail call i32 @getc(i32 %19)
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %6
23: ; preds = %15, %0, %12
%24 = getelementptr inbounds [1025 x i8], [1025 x i8]* %1, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %24)
ret void
}