#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 /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
size_t strcspn(char *, char *);
void get_user_input(char *buffer, int buffer_size, const char *msg) {
  memset(buffer, '\0', buffer_size);
  fprintf(stdout, "%s", msg);
  while (fgets(buffer, buffer_size, stdin) == NULL || buffer[0] == '\n') {
    memset(buffer, '\0', buffer_size);
    fprintf(stdout,
            "Sorry, I did not understand your input.\n"
            "Please re-try:\n%s",
            msg);
  }
  buffer[strcspn(buffer, "\n")] = '\0';
}


x86 assembly (clang, -O0):
<get_user_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xec2(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     11b1 <get_user_input+0x71>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11c1 <get_user_input+0x81>
jmp    11ed <get_user_input+0xad>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe1d(%rip),%rsi
call   1060 <fprintf@plt>
jmp    117a <get_user_input+0x3a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_user_input>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0xedc(%rip),%rbp
mov    0x2e86(%rip),%r13
lea    0xe97(%rip),%r12
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1030 <memset@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    %r15d,%esi
call   1050 <fgets@plt>
mov    %r12,%rbp
test   %rax,%rax
je     1170 <get_user_input+0x30>
cmpb   $0xa,(%rbx)
mov    %r12,%rbp
je     1170 <get_user_input+0x30>
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcspn@plt>
movb   $0x0,(%rbx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [3 x i8] c"%s\00"
@stdin = global i32 0
@.str.1 = [58 x i8] c"Sorry, I did not understand your input.\0APlease re-try:\0A%s\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @get_user_input(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%7 = load i8*, i8** %4
%8 = load i32, i32* %5
%9 = call i32 @memset(i8* %7, i8 signext 0, i32 %8)
%10 = load i32, i32* @stdout
%11 = load i8*, i8** %6
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %27, %3
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = load i32, i32* @stdin
%17 = call i32* @fgets(i8* %14, i32 %15, i32 %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %25, label %19
19: ; preds = %13
%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, 10
br label %25
25: ; preds = %19, %13
%26 = phi i1 [ true, %13 ], [ %24, %19 ]
br i1 %26, label %27, label %34
27: ; preds = %25
%28 = load i8*, i8** %4
%29 = load i32, i32* %5
%30 = call i32 @memset(i8* %28, i8 signext 0, i32 %29)
%31 = load i32, i32* @stdout
%32 = load i8*, i8** %6
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i8* %32)
br label %13
34: ; preds = %25
%35 = load i8*, i8** %4
%36 = load i8*, i8** %4
%37 = call i64 @strcspn(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [3 x i8] c"%s\00"
@stdin = global i32 0
@.str.1 = [58 x i8] c"Sorry, I did not understand your input.\0APlease re-try:\0A%s\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @get_user_input(i8* %0, i32 %1, i8* %2) {
br label %4
4: ; preds = %12, %3
%5 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), %12 ]
%6 = tail call i32 @memset(i8* %0, i8 signext 0, i32 %1)
%7 = load i32, i32* @stdout
%8 = tail call i32 @fprintf(i32 %7, i8* %5, i8* %2)
%9 = load i32, i32* @stdin
%10 = tail call i32* @fgets(i8* %0, i32 %1, i32 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %4, %13
br label %4
13: ; preds = %4
%14 = load i8, i8* %0
%15 = icmp eq i8 %14, 10
br i1 %15, label %12, label %16
16: ; preds = %13
%17 = tail call i64 @strcspn(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 0, i8* %18
ret void
}