#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 /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int read(int /*<<< orphan*/, char *, int);
void getstring(char *bp) {
  int i;
  char *cp = bp;
  for (i = 0; i < 64; i++) {
    if (read(STDIN_FILENO, cp + i, 1) != 1)
      exit(0);
    if (cp[i] == '\n')
      break;
  }
  cp[i] = '\0';
}


x86 assembly (clang, -O0):
<getstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x40,-0xc(%rbp)
jge    11a0 <getstring+0x80>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
je     1173 <getstring+0x53>
xor    %edi,%edi
call   1040 <exit@plt>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    118d <getstring+0x6d>
jmp    11a0 <getstring+0x80>
jmp    1192 <getstring+0x72>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113b <getstring+0x1b>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getstring>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %r15d,%r15d
mov    0x2eab(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12),%edi
lea    (%r14,%r15,1),%rbx
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
jne    1183 <getstring+0x63>
cmpb   $0xa,(%rbx)
je     116f <getstring+0x4f>
add    $0x1,%r15
cmp    $0x40,%r15
jne    1140 <getstring+0x20>
mov    $0x40,%r15d
mov    %r15d,%eax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %edi,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
define void @getstring(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %4
store i32 0, i32* %3
br label %6
6: ; preds = %29, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 64
br i1 %8, label %9, label %32
9: ; preds = %6
%10 = load i32, i32* @STDIN_FILENO
%11 = load i8*, i8** %4
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = call i32 @read(i32 %10, i8* %14, i32 1)
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %9
%20 = load i8*, i8** %4
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 10
br i1 %26, label %27, label %28
27: ; preds = %19
br label %32
28: ; preds = %19
br label %29
29: ; preds = %28
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %6
32: ; preds = %27, %6
%33 = load i8*, i8** %4
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 0, i8* %36
ret void
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
define void @getstring(i8* nocapture %0) {
br label %2
2: ; preds = %1, %13
%3 = phi i64 [ 0, %1 ], [ %14, %13 ]
%4 = load i32, i32* @STDIN_FILENO
%5 = getelementptr inbounds i8, i8* %0, i64 %3
%6 = tail call i32 @read(i32 %4, i8* %5, i32 1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2
%11 = load i8, i8* %5
%12 = icmp eq i8 %11, 10
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = add nuw nsw i64 %3, 1
%15 = icmp eq i64 %14, 64
br i1 %15, label %16, label %2
16: ; preds = %10, %13
%17 = phi i64 [ %3, %10 ], [ 64, %13 ]
%18 = and i64 %17, 4294967295
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 0, i8* %19
ret void
}