#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 *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int get_string(char *string) {
  printf("Please input a string: \n");
  if (NULL == fgets(string, 256, stdin)) {
    fprintf(stderr, "Error: did you input a correct string?\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e95(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    118e <get_string+0x5e>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <get_string+0x65>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_string>:
push   %rbx
mov    %rdi,%rbx
lea    0xeed(%rip),%rdi
call   1030 <puts@plt>
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1162 <get_string+0x32>
pop    %rbx
ret
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Please input a string: \0A\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [40 x i8] c"Error: did you input a correct string?\0A\00"
define i32 @get_string(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%5 = load i8*, i8** %3
%6 = load i32, i32* @stdin
%7 = call i32* @fgets(i8* %5, i32 256, i32 %6)
%8 = icmp eq i32* null, %7
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %13
12: ; preds = %1
store i32 0, i32* %2
br label %13
13: ; preds = %12, %9
%14 = load i32, i32* %2
ret i32 %14
}

LLVM IR (-O2):
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [40 x i8] c"Error: did you input a correct string?\0A\00"
@str = [24 x i8] c"Please input a string: \00"
define i32 @get_string(i8* %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%3 = load i32, i32* @stdin
%4 = tail call i32* @fgets(i8* %0, i32 256, i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %1, %6
%10 = phi i32 [ -1, %6 ], [ 0, %1 ]
ret i32 %10
}