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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sanity_check(char *, int /*<<< orphan*/, char);
int /*<<< orphan*/ stdin;
size_t strcspn(char *, char *);
int strlen(char *);
int GetUserInput(char *_buffer, uint _maxLength) {
  if (!_buffer) {
    return 0;
  }
  do {
    fgets(_buffer, _maxLength, stdin);
    _buffer[strcspn(_buffer, "\n")] = 0;
  } while (_buffer[0] == '\0');
  sanity_check(_buffer, _maxLength, '_');
  return strlen(_buffer);
}


x86 assembly (clang, -O0):
<GetUserInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1166 <GetUserInput+0x26>
movl   $0x0,-0x4(%rbp)
jmp    11d0 <GetUserInput+0x90>
jmp    116b <GetUserInput+0x2b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     116b <GetUserInput+0x2b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x5f,%edx
call   1060 <sanity_check@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetUserInput>:
test   %rdi,%rdi
je     11a2 <GetUserInput+0x62>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2e90(%rip),%r15
lea    0xea1(%rip),%r14
nop
mov    (%r15),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcspn@plt>
movb   $0x0,(%rbx,%rax,1)
cmpb   $0x0,(%rbx)
je     1160 <GetUserInput+0x20>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x5f,%edx
call   1060 <sanity_check@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strlen@plt>
xor    %eax,%eax
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [2 x i8] c"\0A\00"
define i32 @GetUserInput(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %2
store i32 0, i32* %3
br label %31
9: ; preds = %2
br label %10
10: ; preds = %19, %9
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %11, i32 %12, i32 %13)
%15 = load i8*, i8** %4
%16 = load i8*, i8** %4
%17 = call i64 @strcspn(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 0, i8* %18
br label %19
19: ; preds = %10
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %10, label %25
25: ; preds = %19
%26 = load i8*, i8** %4
%27 = load i32, i32* %5
%28 = call i32 @sanity_check(i8* %26, i32 %27, i8 signext 95)
%29 = load i8*, i8** %4
%30 = call i32 @strlen(i8* %29)
store i32 %30, i32* %3
br label %31
31: ; preds = %25, %8
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [2 x i8] c"\0A\00"
define i32 @GetUserInput(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %14, label %4
4: ; preds = %2, %4
%5 = load i32, i32* @stdin
%6 = tail call i32 @fgets(i8* %0, i32 %1, i32 %5)
%7 = tail call i64 @strcspn(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 0, i8* %8
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 0
br i1 %10, label %4, label %11
11: ; preds = %4
%12 = tail call i32 @sanity_check(i8* %0, i32 %1, i8 signext 95)
%13 = tail call i32 @strlen(i8* %0)
br label %14
14: ; preds = %2, %11
%15 = phi i32 [ %13, %11 ], [ 0, %2 ]
ret i32 %15
}