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

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ EIO;
scalar_t__ ENOENT;
int /*<<< orphan*/ TCFLSH;
int /*<<< orphan*/ _isprint(char);
int /*<<< orphan*/ do_prompt();
scalar_t__ errno;
int /*<<< orphan*/ error(char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int /*<<< orphan*/, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int read(int /*<<< orphan*/, char *, int);
char *get_logname() {
  static char logname[40];
  char *c;
  ioctl(0, TCFLSH, 0);
  for (*logname = 0; *logname == 0;) {
    do_prompt();
    for (c = logname;;) {
      if (read(0, c, 1) < 1) {
        if (errno == EINTR || errno == EIO || errno == ENOENT)
          exit(0);
        error("received strange error\n", 9);
      }
      if (*c == '\n' || *c == '\r') {
        *c = 0;
        break;
      } else if (!_isprint(*c))
        error("unprintable character in login name\n", 10);
      else if (c - logname >= sizeof(logname) - 1)
        error("login name too long\n", 11);
      else
        c++;
    }
  }
  return logname;
}


x86 assembly (clang, -O0):
<get_logname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    %edx,%edi
call   1030 <ioctl@plt>
movb   $0x0,0x2edf(%rip)
movsbl 0x2ed8(%rip),%eax
cmp    $0x0,%eax
jne    12c7 <get_logname+0x167>
mov    $0x0,%al
call   1050 <do_prompt@plt>
lea    0x2ec1(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jge    1222 <get_logname+0xc2>
mov    0x2e0d(%rip),%rax
mov    (%rax),%rax
mov    0x2dfb(%rip),%rcx
cmp    (%rcx),%rax
je     120a <get_logname+0xaa>
mov    0x2df3(%rip),%rax
mov    (%rax),%rax
mov    0x2df9(%rip),%rcx
cmp    (%rcx),%rax
je     120a <get_logname+0xaa>
mov    0x2dd9(%rip),%rax
mov    (%rax),%rax
mov    0x2db7(%rip),%rcx
cmp    (%rcx),%rax
jne    1211 <get_logname+0xb1>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xde8(%rip),%rdi
mov    $0x9,%esi
call   1070 <error@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1242 <get_logname+0xe2>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    124e <get_logname+0xee>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    12c2 <get_logname+0x162>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1060 <_isprint@plt>
cmp    $0x0,%eax
jne    1279 <get_logname+0x119>
lea    0xdae(%rip),%rdi
mov    $0xa,%esi
call   1070 <error@plt>
jmp    12b8 <get_logname+0x158>
mov    -0x8(%rbp),%rax
lea    0x2ddc(%rip),%rcx
sub    %rcx,%rax
cmp    $0x27,%rax
jb     12a7 <get_logname+0x147>
lea    0xda5(%rip),%rdi
mov    $0xb,%esi
call   1070 <error@plt>
jmp    12b3 <get_logname+0x153>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    12b8 <get_logname+0x158>
jmp    12bd <get_logname+0x15d>
jmp    11a3 <get_logname+0x43>
jmp    1181 <get_logname+0x21>
lea    0x2d92(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_logname>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
xor    %edx,%edx
call   1030 <ioctl@plt>
movb   $0x0,0x2edc(%rip)
mov    0x2e55(%rip),%r14
mov    0x2e26(%rip),%rbp
lea    0xe67(%rip),%r15
lea    0xe9d(%rip),%r12
jmp    11c0 <get_logname+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,(%rbx)
cmpb   $0x0,0x2ea6(%rip)
jne    1280 <get_logname+0x120>
xor    %eax,%eax
call   1050 <do_prompt@plt>
lea    0x2e92(%rip),%rax
mov    %rax,%rbx
mov    %rbx,%r13
sub    %rax,%r13
jmp    11f1 <get_logname+0x91>
nopl   0x0(%rax)
lea    0xe31(%rip),%rdi
mov    $0xa,%esi
call   1070 <error@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     1232 <get_logname+0xd2>
mov    0x2dc5(%rip),%rax
mov    (%rax),%rax
mov    0x2db3(%rip),%rcx
cmp    (%rcx),%rax
je     1296 <get_logname+0x136>
cmp    (%r14),%rax
je     1296 <get_logname+0x136>
cmp    0x0(%rbp),%rax
je     1296 <get_logname+0x136>
mov    %r15,%rdi
mov    $0x9,%esi
call   1070 <error@plt>
movzbl (%rbx),%eax
cmp    $0xd,%al
je     11b0 <get_logname+0x50>
cmp    $0xa,%al
je     11b0 <get_logname+0x50>
movsbl %al,%edi
call   1060 <_isprint@plt>
test   %eax,%eax
je     11e0 <get_logname+0x80>
cmp    $0x27,%r13
jb     1270 <get_logname+0x110>
mov    %r12,%rdi
mov    $0xb,%esi
call   1070 <error@plt>
jmp    11f1 <get_logname+0x91>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
lea    0x2de5(%rip),%rax
jmp    11d1 <get_logname+0x71>
lea    0x2dd9(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@get_logname.logname = internal global [40 x i8] zeroinitializer
@TCFLSH = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@EIO = global i64 0
@ENOENT = global i64 0
@.str = [24 x i8] c"received strange error\0A\00"
@.str.1 = [37 x i8] c"unprintable character in login name\0A\00"
@.str.2 = [21 x i8] c"login name too long\0A\00"
define i8* @get_logname() {
%1 = alloca i8*
%2 = load i32, i32* @TCFLSH
%3 = call i32 @ioctl(i32 0, i32 %2, i32 0)
store i8 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @get_logname.logname, i64 0, i64 0)
br label %4
4: ; preds = %62, %0
%5 = load i8, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @get_logname.logname, i64 0, i64 0)
%6 = sext i8 %5 to i32
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %63
8: ; preds = %4
%9 = call i32 (...) @do_prompt()
store i8* getelementptr inbounds ([40 x i8], [40 x i8]* @get_logname.logname, i64 0, i64 0), i8** %1
br label %10
10: ; preds = %61, %8
%11 = load i8*, i8** %1
%12 = call i32 @read(i32 0, i8* %11, i32 1)
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %30
14: ; preds = %10
%15 = load i64, i64* @errno
%16 = load i64, i64* @EINTR
%17 = icmp eq i64 %15, %16
br i1 %17, label %26, label %18
18: ; preds = %14
%19 = load i64, i64* @errno
%20 = load i64, i64* @EIO
%21 = icmp eq i64 %19, %20
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i64, i64* @errno
%24 = load i64, i64* @ENOENT
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %22, %18, %14
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %22
%29 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 9)
br label %30
30: ; preds = %28, %10
%31 = load i8*, i8** %1
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %40, label %35
35: ; preds = %30
%36 = load i8*, i8** %1
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 13
br i1 %39, label %40, label %42
40: ; preds = %35, %30
%41 = load i8*, i8** %1
store i8 0, i8* %41
br label %62
42: ; preds = %35
%43 = load i8*, i8** %1
%44 = load i8, i8* %43
%45 = call i32 @_isprint(i8 signext %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %42
%48 = call i32 @error(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 10)
br label %60
49: ; preds = %42
%50 = load i8*, i8** %1
%51 = ptrtoint i8* %50 to i64
%52 = sub i64 %51, ptrtoint ([40 x i8]* @get_logname.logname to i64)
%53 = icmp uge i64 %52, 39
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 11)
br label %59
56: ; preds = %49
%57 = load i8*, i8** %1
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %1
br label %59
59: ; preds = %56, %54
br label %60
60: ; preds = %59, %47
br label %61
61: ; preds = %60
br label %10
62: ; preds = %40
br label %4
63: ; preds = %4
ret i8* getelementptr inbounds ([40 x i8], [40 x i8]* @get_logname.logname, i64 0, i64 0)
}

LLVM IR (-O2):
@get_logname.logname = internal global [40 x i8] zeroinitializer
@TCFLSH = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@EIO = global i64 0
@ENOENT = global i64 0
@.str = [24 x i8] c"received strange error\0A\00"
@.str.1 = [37 x i8] c"unprintable character in login name\0A\00"
@.str.2 = [21 x i8] c"login name too long\0A\00"
define i8* @get_logname() {
%1 = load i32, i32* @TCFLSH
%2 = tail call i32 @ioctl(i32 0, i32 %1, i32 0)
store i8 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @get_logname.logname, i64 0, i64 0)
br label %3
3: ; preds = %0, %29
%4 = tail call i32 (...) @do_prompt()
br label %5
5: ; preds = %41, %3
%6 = phi i8* [ %42, %41 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @get_logname.logname, i64 0, i64 0), %3 ]
%7 = ptrtoint i8* %6 to i64
%8 = sub i64 %7, ptrtoint ([40 x i8]* @get_logname.logname to i64)
%9 = icmp ugt i64 %8, 38
br label %10
10: ; preds = %37, %5
%11 = tail call i32 @read(i32 0, i8* %6, i32 1)
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %27
13: ; preds = %10
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
%17 = load i64, i64* @EIO
%18 = icmp eq i64 %14, %17
%19 = select i1 %16, i1 true, i1 %18
%20 = load i64, i64* @ENOENT
%21 = icmp eq i64 %14, %20
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = tail call i32 @exit(i32 0)
unreachable
25: ; preds = %13
%26 = tail call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 9)
br label %27
27: ; preds = %25, %10
%28 = load i8, i8* %6
switch i8 %28, label %32 [
i8 10, label %29
i8 13, label %29
]
29: ; preds = %27, %27
store i8 0, i8* %6
%30 = load i8, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @get_logname.logname, i64 0, i64 0)
%31 = icmp eq i8 %30, 0
br i1 %31, label %3, label %43
32: ; preds = %27
%33 = tail call i32 @_isprint(i8 signext %28)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = tail call i32 @error(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 10)
br label %37
37: ; preds = %35, %39
br label %10
38: ; preds = %32
br i1 %9, label %39, label %41
39: ; preds = %38
%40 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 11)
br label %37
41: ; preds = %38
%42 = getelementptr inbounds i8, i8* %6, i64 1
br label %5
43: ; preds = %29
ret i8* getelementptr inbounds ([40 x i8], [40 x i8]* @get_logname.logname, i64 0, i64 0)
}