#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 EOF;
int getc(int /*<<< orphan*/);
int /*<<< orphan*/ isalnum(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
void safeget(char *buf, int maxlen) {
  int c, i = 0, bad = 0;
  char *bstart = buf;
  while ((c = getc(stdin)) != EOF && (c != '\n') && (++i < maxlen)) {
    bad = (!isalnum(c) && (c != '_') && (c != ' '));
    *(buf++) = (char)c;
  }
  *buf = '\0';
  if (bad) {
    printf("\nString contained banned character. Please stick to "
           "alphanumerics.\n");
    *bstart = '\0';
  }
}


x86 assembly (clang, -O0):
<safeget>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
call   1050 <getc@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
xor    %eax,%eax
mov    0x2e6f(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x21(%rbp)
je     119d <safeget+0x6d>
xor    %eax,%eax
cmpl   $0xa,-0x10(%rbp)
mov    %al,-0x21(%rbp)
je     119d <safeget+0x6d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ad <safeget+0x7d>
jmp    1204 <safeget+0xd4>
mov    -0x10(%rbp),%edi
call   1040 <isalnum@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x22(%rbp)
jne    11de <safeget+0xae>
xor    %eax,%eax
cmpl   $0x5f,-0x10(%rbp)
mov    %al,-0x22(%rbp)
je     11de <safeget+0xae>
cmpl   $0x20,-0x10(%rbp)
setne  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    1155 <safeget+0x25>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x18(%rbp)
je     1228 <safeget+0xf8>
lea    0xde4(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safeget>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
call   1050 <getc@plt>
cmp    $0xa,%eax
je     11d3 <safeget+0xa3>
mov    0x2e82(%rip),%r12
cmp    (%r12),%eax
je     11d3 <safeget+0xa3>
cmp    $0x2,%ebx
mov    $0x1,%ecx
cmovge %ebx,%ecx
cmp    $0x1,%ecx
je     11d3 <safeget+0xa3>
mov    %ecx,%r13d
add    $0xfffffffffffffffe,%r13
xor    %r15d,%r15d
xchg   %ax,%ax
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <isalnum@plt>
mov    %eax,%ebx
mov    %bpl,(%r14,%r15,1)
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1050 <getc@plt>
lea    0x1(%r15),%rcx
cmp    $0xa,%eax
je     11b4 <safeget+0x84>
cmp    (%r12),%eax
je     11b4 <safeget+0x84>
cmp    %r15d,%r13d
mov    %rcx,%r15
jne    1180 <safeget+0x50>
movb   $0x0,(%r14,%rcx,1)
test   %ebx,%ebx
jne    11d7 <safeget+0xa7>
cmp    $0x20,%ebp
je     11d7 <safeget+0xa7>
cmp    $0x5f,%ebp
je     11d7 <safeget+0xa7>
lea    0xe32(%rip),%rdi
call   1030 <puts@plt>
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i32 0
@.str = [68 x i8] c"\0AString contained banned character. Please stick to alphanumerics.\0A\00"
define void @safeget(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i32 0, i32* %7
%9 = load i8*, i8** %3
store i8* %9, i8** %8
br label %10
10: ; preds = %35, %2
%11 = load i32, i32* @stdin
%12 = call i32 @getc(i32 %11)
store i32 %12, i32* %5
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %23
15: ; preds = %10
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 10
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br label %23
23: ; preds = %18, %15, %10
%24 = phi i1 [ false, %15 ], [ false, %10 ], [ %22, %18 ]
br i1 %24, label %25, label %42
25: ; preds = %23
%26 = load i32, i32* %5
%27 = call i32 @isalnum(i32 %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %35, label %29
29: ; preds = %25
%30 = load i32, i32* %5
%31 = icmp ne i32 %30, 95
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* %5
%34 = icmp ne i32 %33, 32
br label %35
35: ; preds = %32, %29, %25
%36 = phi i1 [ false, %29 ], [ false, %25 ], [ %34, %32 ]
%37 = zext i1 %36 to i32
store i32 %37, i32* %7
%38 = load i32, i32* %5
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %3
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %3
store i8 %39, i8* %40
br label %10
42: ; preds = %23
%43 = load i8*, i8** %3
store i8 0, i8* %43
%44 = load i32, i32* %7
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%48 = load i8*, i8** %8
store i8 0, i8* %48
br label %49
49: ; preds = %46, %42
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
@str = [67 x i8] c"\0AString contained banned character. Please stick to alphanumerics.\00"
define void @safeget(i8* nocapture writeonly %0, i32 %1) {
%3 = load i32, i32* @stdin
%4 = tail call i32 @getc(i32 %3)
%5 = load i32, i32* @EOF
%6 = icmp ne i32 %4, %5
%7 = icmp ne i32 %4, 10
%8 = and i1 %7, %6
br i1 %8, label %9, label %35
9: ; preds = %2
%10 = call i32 @llvm.smax.i32(i32 %1, i32 1)
%11 = add nsw i32 %10, -1
%12 = icmp eq i32 %11, 0
br i1 %12, label %35, label %13
13: ; preds = %9, %13
%14 = phi i32 [ %17, %13 ], [ 0, %9 ]
%15 = phi i8* [ %20, %13 ], [ %0, %9 ]
%16 = phi i32 [ %22, %13 ], [ %4, %9 ]
%17 = add nuw nsw i32 %14, 1
%18 = tail call i32 @isalnum(i32 %16)
%19 = trunc i32 %16 to i8
%20 = getelementptr inbounds i8, i8* %15, i64 1
store i8 %19, i8* %15
%21 = load i32, i32* @stdin
%22 = tail call i32 @getc(i32 %21)
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
%25 = icmp eq i32 %22, 10
%26 = or i1 %25, %24
%27 = icmp eq i32 %17, %11
%28 = select i1 %26, i1 true, i1 %27
br i1 %28, label %29, label %13
29: ; preds = %13
%30 = freeze i32 %18
%31 = icmp eq i32 %30, 0
store i8 0, i8* %20
br i1 %31, label %32, label %36
32: ; preds = %29
switch i32 %16, label %33 [
i32 95, label %36
i32 32, label %36
]
33: ; preds = %32
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str, i64 0, i64 0))
br label %35
35: ; preds = %9, %33, %2
store i8 0, i8* %0
br label %36
36: ; preds = %35, %32, %32, %29
ret void
}