#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*/ logg(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
void readAndPrint() {
  logg("readAndPrint");
  char buff[300];
  while (fgets(buff, sizeof(buff), stdin)) {
    logg("inside");
    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    0xeae(%rip),%rdi
call   1060 <logg@plt>
lea    -0x130(%rbp),%rdi
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
mov    $0x12c,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11cb <readAndPrint+0x8b>
lea    0xe8b(%rip),%rdi
call   1060 <logg@plt>
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    11ba <readAndPrint+0x7a>
jmp    11cb <readAndPrint+0x8b>
lea    -0x130(%rbp),%rdi
call   1030 <puts@plt>
jmp    1157 <readAndPrint+0x17>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readAndPrint>:
push   %r15
push   %r14
push   %rbx
sub    $0x130,%rsp
lea    0xead(%rip),%rdi
call   1060 <logg@plt>
mov    0x2e89(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x12c,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11c0 <readAndPrint+0x80>
lea    0xe8f(%rip),%r14
xchg   %ax,%ax
mov    %r14,%rdi
call   1060 <logg@plt>
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     11c0 <readAndPrint+0x80>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x12c,%esi
call   1050 <fgets@plt>
test   %rax,%rax
jne    1180 <readAndPrint+0x40>
add    $0x130,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"readAndPrint\00"
@stdin = global i32 0
@.str.1 = [7 x i8] c"inside\00"
define void @readAndPrint() {
%1 = alloca [300 x i8]
%2 = tail call i32 @logg(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 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 eq i64 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %0, %15
%8 = call i32 @logg(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @strlen(i8* %3)
%10 = add 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 = call i32 @strlen(i8* %3)
%14 = icmp eq i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %7
%16 = call i32 @puts(i8* %3)
%17 = load i32, i32* @stdin
%18 = call i64 @fgets(i8* %3, i32 300, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %7
20: ; preds = %15, %7, %0
ret void
}