#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
void readstr(char *prompt, char *stringvar, int maxlen) {
  do {
    printf("%s", prompt);
    fgets(stringvar, maxlen, stdin);
    if (stringvar[strlen(stringvar) - 1] == '\n')
      stringvar[strlen(stringvar) - 1] = 0;
  } while (strlen(stringvar) == 0);
}


x86 assembly (clang, -O0):
<readstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11b3 <readstr+0x83>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11b8 <readstr+0x88>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
je     1143 <readstr+0x13>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xeb8(%rip),%r15
mov    0x2e99(%rip),%r12
jmp    116c <readstr+0x3c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jne    11a8 <readstr+0x78>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1160 <readstr+0x30>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
jmp    1160 <readstr+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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