#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*/ _zap_trailing_whitespace(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *xreadline(char *prompt, char *buf, int buflen) {
  printf("%s", prompt);
  fflush(stdout);
  if (fgets(buf, buflen, stdin) == NULL)
    return NULL;
  _zap_trailing_whitespace(buf);
  return buf;
}


x86 assembly (clang, -O0):
<xreadline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    119d <xreadline+0x5d>
movq   $0x0,-0x8(%rbp)
jmp    11ae <xreadline+0x6e>
mov    -0x18(%rbp),%rdi
call   1040 <_zap_trailing_whitespace@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xreadline>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%rsi
lea    0xeae(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     1187 <xreadline+0x47>
mov    %rbx,%rdi
call   1040 <_zap_trailing_whitespace@plt>
jmp    1189 <xreadline+0x49>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@stdout = global i32 0
@stdin = global i32 0
define i8* @xreadline(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i8*, i8** %5
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @stdout
%11 = call i32 @fflush(i32 %10)
%12 = load i8*, i8** %6
%13 = load i32, i32* %7
%14 = load i32, i32* @stdin
%15 = call i32* @fgets(i8* %12, i32 %13, i32 %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %3
store i8* null, i8** %4
br label %22
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = call i32 @_zap_trailing_whitespace(i8* %19)
%21 = load i8*, i8** %6
store i8* %21, i8** %4
br label %22
22: ; preds = %18, %17
%23 = load i8*, i8** %4
ret i8* %23
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@stdout = global i32 0
@stdin = global i32 0
define i8* @xreadline(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = load i32, i32* @stdout
%6 = tail call i32 @fflush(i32 %5)
%7 = load i32, i32* @stdin
%8 = tail call i32* @fgets(i8* %1, i32 %2, i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = tail call i32 @_zap_trailing_whitespace(i8* %1)
br label %12
12: ; preds = %3, %10
%13 = phi i8* [ %1, %10 ], [ null, %3 ]
ret i8* %13
}