#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 */
char EOF;
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/);
char getchar();
char scanf(char *, char *);
int /*<<< orphan*/ stdout;
int validated_or_get_len(char *);
int getuname(const char *prompt, char *uname) {
  char c, rv;
  fputs(prompt, stdout);
  rv = scanf("%10s", uname);
  while ('\n' != (c = getchar()) && EOF != c)
    ;
  if (rv != 1) {
    return 0;
  }
  return validated_or_get_len(uname);
}


x86 assembly (clang, -O0):
<getuname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    -0x18(%rbp),%rsi
lea    0xe93(%rip),%rdi
call   1060 <scanf@plt>
mov    %al,-0x1a(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%edx
xor    %eax,%eax
mov    $0xa,%ecx
cmp    %edx,%ecx
mov    %al,-0x1b(%rbp)
je     11aa <getuname+0x6a>
mov    0x2e4d(%rip),%rax
movsbl (%rax),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x1b(%rbp)
mov    -0x1b(%rbp),%al
test   $0x1,%al
jne    11ba <getuname+0x7a>
jmp    11bf <getuname+0x7f>
jmp    1175 <getuname+0x35>
movsbl -0x1a(%rbp),%eax
cmp    $0x1,%eax
je     11d8 <getuname+0x98>
movl   $0x0,-0x4(%rbp)
jmp    11e4 <getuname+0xa4>
mov    -0x18(%rbp),%rdi
call   1030 <validated_or_get_len@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getuname>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
lea    0xea4(%rip),%rdi
mov    %r14,%rsi
call   1060 <scanf@plt>
mov    %eax,%ebp
mov    0x2e7b(%rip),%rbx
nopl   (%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     117f <getuname+0x3f>
cmp    %al,(%rbx)
jne    1170 <getuname+0x30>
cmp    $0x1,%bpl
jne    1191 <getuname+0x51>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <validated_or_get_len@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@stdout = global i32 0
@.str = [5 x i8] c"%10s\00"
@EOF = global i8 0
define i32 @getuname(i8* %0, i8* %1) {
%3 = load i32, i32* @stdout
%4 = tail call i32 @fputs(i8* %0, i32 %3)
%5 = tail call signext i8 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %6
6: ; preds = %6, %2
%7 = tail call signext i8 (...) @getchar()
%8 = icmp ne i8 %7, 10
%9 = load i8, i8* @EOF
%10 = icmp ne i8 %9, %7
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %6, label %12
12: ; preds = %6
%13 = icmp eq i8 %5, 1
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i32 @validated_or_get_len(i8* %1)
br label %16
16: ; preds = %12, %14
%17 = phi i32 [ %15, %14 ], [ 0, %12 ]
ret i32 %17
}