#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*/ newline();
int /*<<< orphan*/ print(unsigned char *);
unsigned char readchar_blocking();
void readString(unsigned char *str) {
  unsigned char cc[2];
  unsigned char ch;
  cc[1] = 0;
  ch = readchar_blocking();
  while (ch != 13) {
    *str = ch;
    str++;
    cc[0] = ch;
    print(cc);
    ch = readchar_blocking();
  }
  *str = 0;
  newline();
}


x86 assembly (clang, -O0):
<readString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
mov    $0x0,%al
call   1050 <readchar_blocking@plt>
mov    %al,-0xb(%rbp)
movzbl -0xb(%rbp),%eax
cmp    $0xd,%eax
je     118a <readString+0x5a>
mov    -0xb(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0xb(%rbp),%al
mov    %al,-0xa(%rbp)
lea    -0xa(%rbp),%rdi
call   1040 <print@plt>
mov    $0x0,%al
call   1050 <readchar_blocking@plt>
mov    %al,-0xb(%rbp)
jmp    114a <readString+0x1a>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x0,%al
call   1030 <newline@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readString>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movb   $0x0,0x7(%rsp)
xor    %eax,%eax
call   1050 <readchar_blocking@plt>
cmp    $0xd,%al
je     116d <readString+0x3d>
lea    0x6(%rsp),%r14
nopl   0x0(%rax)
mov    %al,(%rbx)
add    $0x1,%rbx
mov    %al,0x6(%rsp)
mov    %r14,%rdi
call   1040 <print@plt>
xor    %eax,%eax
call   1050 <readchar_blocking@plt>
cmp    $0xd,%al
jne    1150 <readString+0x20>
movb   $0x0,(%rbx)
xor    %eax,%eax
call   1030 <newline@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @readString(i8* %0) {
%2 = alloca i8*
%3 = alloca [2 x i8]
%4 = alloca i8
store i8* %0, i8** %2
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 0, i8* %5
%6 = call zeroext i8 (...) @readchar_blocking()
store i8 %6, i8* %4
br label %7
7: ; preds = %11, %1
%8 = load i8, i8* %4
%9 = zext i8 %8 to i32
%10 = icmp ne i32 %9, 13
br i1 %10, label %11, label %21
11: ; preds = %7
%12 = load i8, i8* %4
%13 = load i8*, i8** %2
store i8 %12, i8* %13
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %2
%16 = load i8, i8* %4
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
store i8 %16, i8* %17
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%19 = call i32 @print(i8* %18)
%20 = call zeroext i8 (...) @readchar_blocking()
store i8 %20, i8* %4
br label %7
21: ; preds = %7
%22 = load i8*, i8** %2
store i8 0, i8* %22
%23 = call i32 (...) @newline()
ret void
}

LLVM IR (-O2):
define void @readString(i8* nocapture writeonly %0) {
%2 = alloca [2 x i8]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
store i8 0, i8* %4
%5 = tail call zeroext i8 (...) @readchar_blocking()
%6 = icmp eq i8 %5, 13
br i1 %6, label %14, label %7
7: ; preds = %1, %7
%8 = phi i8 [ %12, %7 ], [ %5, %1 ]
%9 = phi i8* [ %10, %7 ], [ %0, %1 ]
store i8 %8, i8* %9
%10 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %8, i8* %3
%11 = call i32 @print(i8* %3)
%12 = call zeroext i8 (...) @readchar_blocking()
%13 = icmp eq i8 %12, 13
br i1 %13, label %14, label %7
14: ; preds = %7, %1
%15 = phi i8* [ %0, %1 ], [ %10, %7 ]
store i8 0, i8* %15
%16 = call i32 (...) @newline()
ret void
}