#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 *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strtok(char *, char *);
char *user_input(char *buffer, char *node_name) {
  printf("Enter the %s:\n", node_name);
  if (fgets(buffer, 256, stdin) == NULL) {
    fprintf(stderr, "failed to read string\n");
    return NULL;
  }
  strtok(buffer, "\n");
  return buffer;
}


x86 assembly (clang, -O0):
<user_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    11a3 <user_input+0x63>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11bb <user_input+0x7b>
mov    -0x10(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1060 <strtok@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<user_input>:
push   %rbx
mov    %rdi,%rbx
lea    0xeb5(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e91(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     117c <user_input+0x3c>
lea    0xe9b(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strtok@plt>
jmp    1193 <user_input+0x53>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1050 <fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Enter the %s:\0A\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed to read string\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
define i8* @user_input(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %5
%7 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %4
%9 = load i32, i32* @stdin
%10 = call i32* @fgets(i8* %8, i32 256, i32 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %3
br label %19
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call i32 @strtok(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = load i8*, i8** %4
store i8* %18, i8** %3
br label %19
19: ; preds = %15, %12
%20 = load i8*, i8** %3
ret i8* %20
}

LLVM IR (-O2):
@.str = [15 x i8] c"Enter the %s:\0A\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed to read string\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
define i8* @user_input(i8* %0, i8* %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %1)
%4 = load i32, i32* @stdin
%5 = tail call i32* @fgets(i8* %0, i32 256, i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %12
10: ; preds = %2
%11 = tail call i32 @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = phi i8* [ null, %7 ], [ %0, %10 ]
ret i8* %13
}