#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 */
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
void readAndPrint() {
  char buff[300];
  while (fgets(buff, sizeof(buff), stdin)) {
    buff[strlen(buff) - 1] = '\0';
    if (strlen(buff) == 0)
      break;
    puts(buff);
  }
}


x86 assembly (clang, -O0):
<readAndPrint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
lea    -0x130(%rbp),%rdi
mov    0x2e9f(%rip),%rax
mov    (%rax),%edx
mov    $0x12c,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11a3 <readAndPrint+0x73>
lea    -0x130(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x130(%rbp,%rax,1)
lea    -0x130(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jne    1192 <readAndPrint+0x62>
jmp    11a3 <readAndPrint+0x73>
lea    -0x130(%rbp),%rdi
call   1030 <puts@plt>
jmp    113b <readAndPrint+0xb>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readAndPrint>:
push   %r14
push   %rbx
sub    $0x138,%rsp
mov    0x2ea7(%rip),%r14
mov    (%r14),%edx
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x12c,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     118a <readAndPrint+0x5a>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     118a <readAndPrint+0x5a>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    (%r14),%edx
jmp    1150 <readAndPrint+0x20>
add    $0x138,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32 0
define void @readAndPrint() {
%1 = alloca [300 x i8]
br label %2
2: ; preds = %17, %0
%3 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%4 = load i32, i32* @stdin
%5 = call i64 @fgets(i8* %3, i32 300, i32 %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %2
%8 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%9 = call i32 @strlen(i8* %8)
%10 = sub nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 %11
store i8 0, i8* %12
%13 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %7
br label %20
17: ; preds = %7
%18 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%19 = call i32 @puts(i8* %18)
br label %2
20: ; preds = %16, %2
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
define void @readAndPrint() {
%1 = alloca [300 x i8]
%2 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i64 @fgets(i8* %2, i32 300, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %0, %13
%7 = call i32 @strlen(i8* %2)
%8 = add nsw i32 %7, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 %9
store i8 0, i8* %10
%11 = call i32 @strlen(i8* %2)
%12 = icmp eq i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %6
%14 = call i32 @puts(i8* %2)
%15 = load i32, i32* @stdin
%16 = call i64 @fgets(i8* %2, i32 300, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %13, %6, %0
ret void
}