#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*/ buf;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ _login_error(char *, int);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
size_t strlen(char *);
char const *_do_ask_username(void) {
  static char buf[256];
  size_t len;
  int c;
  fputs("login: ", stderr);
  if (fgets(buf, sizeof(buf), stdin) == NULL) {
    if (!feof(stdin))
      _login_error("fgets", 1);
    return NULL;
  }
  if ((len = strlen(buf)) == 0 || buf[0] == '\n')
    return "";
  if (buf[len - 1] == '\n') {
    buf[len - 1] = '\0';
    return buf;
  }
  while ((c = fgetc(stdin)) != EOF && c != '\n')
    ;
  return NULL;
}


x86 assembly (clang, -O0):
<_do_ask_username>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edx
lea    0x2ed3(%rip),%rdi
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    11d6 <_do_ask_username+0x76>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1070 <feof@plt>
cmp    $0x0,%eax
jne    11c9 <_do_ask_username+0x69>
lea    0xe49(%rip),%rdi
mov    $0x1,%esi
call   1080 <_login_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    12a2 <_do_ask_username+0x142>
lea    0x2e83(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1200 <_do_ask_username+0xa0>
movsbl 0x2e69(%rip),%eax
cmp    $0xa,%eax
jne    1210 <_do_ask_username+0xb0>
lea    0xe00(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12a2 <_do_ask_username+0x142>
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
lea    0x2e41(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    124f <_do_ask_username+0xef>
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
lea    0x2e25(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e1a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12a2 <_do_ask_username+0x142>
jmp    1254 <_do_ask_username+0xf4>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   1050 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
mov    0x2d70(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x15(%rbp)
je     1285 <_do_ask_username+0x125>
cmpl   $0xa,-0x14(%rbp)
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1295 <_do_ask_username+0x135>
jmp    129a <_do_ask_username+0x13a>
jmp    1254 <_do_ask_username+0xf4>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_do_ask_username>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e64(%rip),%r12
mov    (%r12),%edx
lea    0x2ed1(%rip),%rdi
mov    $0x100,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11d5 <_do_ask_username+0x75>
lea    0x2ebb(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0xe53(%rip),%r15
test   %rax,%rax
je     11f6 <_do_ask_username+0x96>
cmpb   $0xa,0x2ea0(%rip)
je     11f6 <_do_ask_username+0x96>
cmpb   $0xa,-0x1(%rax,%r14,1)
jne    1205 <_do_ask_username+0xa5>
movb   $0x0,-0x1(%rax,%r14,1)
mov    %r14,%r15
jmp    11f6 <_do_ask_username+0x96>
mov    (%r12),%edi
call   1070 <feof@plt>
test   %eax,%eax
jne    11f3 <_do_ask_username+0x93>
lea    0xe1f(%rip),%rdi
mov    $0x1,%esi
call   1080 <_login_error@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dd4(%rip),%rbx
xor    %r15d,%r15d
nop
mov    (%r12),%edi
call   1050 <fgetc@plt>
cmp    $0xa,%eax
je     11f6 <_do_ask_username+0x96>
cmp    (%rbx),%eax
jne    1210 <_do_ask_username+0xb0>
jmp    11f6 <_do_ask_username+0x96>

LLVM IR (-O0):
@_do_ask_username.buf = internal global [256 x i8] zeroinitializer
@.str = [8 x i8] c"login: \00"
@stderr = global i32 0
@stdin = global i32 0
@.str.1 = [6 x i8] c"fgets\00"
@.str.2 = [1 x i8] zeroinitializer
@EOF = global i32 0
define i8* @_do_ask_username() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i32
%4 = load i32, i32* @stderr
%5 = call i32 @fputs(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @stdin
%7 = call i32* @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_do_ask_username.buf, i64 0, i64 0), i32 256, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %16
9: ; preds = %0
%10 = load i32, i32* @stdin
%11 = call i32 @feof(i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i32 @_login_error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %15
15: ; preds = %13, %9
store i8* null, i8** %1
br label %48
16: ; preds = %0
%17 = call i64 @strlen(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_do_ask_username.buf, i64 0, i64 0))
store i64 %17, i64* %2
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %16
%20 = load i8, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_do_ask_username.buf, i64 0, i64 0)
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %19, %16
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8** %1
br label %48
24: ; preds = %19
%25 = load i64, i64* %2
%26 = sub i64 %25, 1
%27 = getelementptr inbounds [256 x i8], [256 x i8]* @_do_ask_username.buf, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 10
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = load i64, i64* %2
%33 = sub i64 %32, 1
%34 = getelementptr inbounds [256 x i8], [256 x i8]* @_do_ask_username.buf, i64 0, i64 %33
store i8 0, i8* %34
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_do_ask_username.buf, i64 0, i64 0), i8** %1
br label %48
35: ; preds = %24
br label %36
36: ; preds = %46, %35
%37 = load i32, i32* @stdin
%38 = call i32 @fgetc(i32 %37)
store i32 %38, i32* %3
%39 = load i32, i32* @EOF
%40 = icmp ne i32 %38, %39
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i32, i32* %3
%43 = icmp ne i32 %42, 10
br label %44
44: ; preds = %41, %36
%45 = phi i1 [ false, %36 ], [ %43, %41 ]
br i1 %45, label %46, label %47
46: ; preds = %44
br label %36
47: ; preds = %44
store i8* null, i8** %1
br label %48
48: ; preds = %47, %31, %23, %15
%49 = load i8*, i8** %1
ret i8* %49
}

LLVM IR (-O2):
@_do_ask_username.buf = internal global [256 x i8] zeroinitializer
@.str = [8 x i8] c"login: \00"
@stderr = global i32 0
@stdin = global i32 0
@.str.1 = [6 x i8] c"fgets\00"
@.str.2 = [1 x i8] zeroinitializer
@EOF = global i32 0
define i8* @_do_ask_username() {
%1 = load i32, i32* @stderr
%2 = tail call i32 @fputs(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = load i32, i32* @stdin
%4 = tail call i32* @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_do_ask_username.buf, i64 0, i64 0), i32 256, i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = load i32, i32* @stdin
%8 = tail call i32 @feof(i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %31
10: ; preds = %6
%11 = tail call i32 @_login_error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %31
12: ; preds = %0
%13 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @_do_ask_username.buf, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
%15 = load i8, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_do_ask_username.buf, i64 0, i64 0)
%16 = icmp eq i8 %15, 10
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %31, label %18
18: ; preds = %12
%19 = add i64 %13, -1
%20 = getelementptr inbounds [256 x i8], [256 x i8]* @_do_ask_username.buf, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %18
store i8 0, i8* %20
br label %31
24: ; preds = %18, %24
%25 = load i32, i32* @stdin
%26 = tail call i32 @fgetc(i32 %25)
%27 = load i32, i32* @EOF
%28 = icmp ne i32 %26, %27
%29 = icmp ne i32 %26, 10
%30 = and i1 %29, %28
br i1 %30, label %24, label %31
31: ; preds = %24, %12, %6, %10, %23
%32 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @_do_ask_username.buf, i64 0, i64 0), %23 ], [ null, %10 ], [ null, %6 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %12 ], [ null, %24 ]
ret i8* %32
}