#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*/ free(char *);
size_t getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
scalar_t__ strlen(char *);
char *get_string() {
  size_t size = 0;
  char *ptr = NULL;
  size = getline(&ptr, &size, stdin);
  if ((int)size == -1) {
    printf("\n");
    return NULL;
  } else {
    ptr[size - 1] = '\0';
  }
  if ((int)size == -1 || strlen(ptr) <= 0) {
    free(ptr);
    printf("You may not input an empty string: ");
    return get_string();
  }
  return ptr;
}


x86 assembly (clang, -O0):
<get_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <getline@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    $0xffffffff,%eax
jne    11a8 <get_string+0x58>
lea    0xe6a(%rip),%rdi
call   1060 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1203 <get_string+0xb3>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
cmp    $0xffffffff,%eax
je     11d8 <get_string+0x88>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jg     11fb <get_string+0xab>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe1a(%rip),%rdi
call   1060 <printf@plt>
call   1050 <get_string@plt>
mov    %rax,-0x8(%rbp)
jmp    1203 <get_string+0xb3>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_string>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1080 <getline@plt>
mov    %rax,0x8(%rsp)
cmp    $0xffffffff,%eax
je     11d5 <get_string+0x75>
mov    (%rsp),%rcx
movb   $0x0,-0x1(%rax,%rcx,1)
cmpl   $0xffffffff,0x8(%rsp)
mov    (%rsp),%rbx
je     11b7 <get_string+0x57>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
jg     11e1 <get_string+0x81>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe3a(%rip),%rdi
call   1070 <printf@plt>
call   1060 <get_string@plt>
mov    %rax,%rbx
jmp    11e1 <get_string+0x81>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [36 x i8] c"You may not input an empty string: \00"
define i8* @get_string() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i8*
store i64 0, i64* %2
store i8* null, i8** %3
%4 = load i32, i32* @stdin
%5 = call i64 @getline(i8** %3, i64* %2, i32 %4)
store i64 %5, i64* %2
%6 = load i64, i64* %2
%7 = trunc i64 %6 to i32
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %1
br label %31
11: ; preds = %0
%12 = load i8*, i8** %3
%13 = load i64, i64* %2
%14 = sub i64 %13, 1
%15 = getelementptr inbounds i8, i8* %12, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %11
%17 = load i64, i64* %2
%18 = trunc i64 %17 to i32
%19 = icmp eq i32 %18, -1
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = call i64 @strlen(i8* %21)
%23 = icmp sle i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %20, %16
%25 = load i8*, i8** %3
%26 = call i32 @free(i8* %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%28 = call i8* @get_string()
store i8* %28, i8** %1
br label %31
29: ; preds = %20
%30 = load i8*, i8** %3
store i8* %30, i8** %1
br label %31
31: ; preds = %29, %24, %9
%32 = load i8*, i8** %1
ret i8* %32
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [36 x i8] c"You may not input an empty string: \00"
define i8* @get_string() {
%1 = alloca i64
%2 = alloca i8*
%3 = bitcast i64* %1 to i8*
store i64 0, i64* %1
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = load i32, i32* @stdin
%6 = call i64 @getline(i8** %2, i64* %1, i32 %5)
store i64 %6, i64* %1
%7 = trunc i64 %6 to i32
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @putchar(i32 10)
br label %26
11: ; preds = %0
%12 = load i8*, i8** %2
%13 = add i64 %6, -1
%14 = getelementptr inbounds i8, i8* %12, i64 %13
store i8 0, i8* %14
%15 = load i64, i64* %1
%16 = trunc i64 %15 to i32
%17 = icmp eq i32 %16, -1
%18 = load i8*, i8** %2
br i1 %17, label %22, label %19
19: ; preds = %11
%20 = call i64 @strlen(i8* dereferenceable(1) %18)
%21 = icmp slt i64 %20, 1
br i1 %21, label %22, label %26
22: ; preds = %11, %19
%23 = call i32 @free(i8* %18)
%24 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%25 = call i8* @get_string()
br label %26
26: ; preds = %19, %22, %9
%27 = phi i8* [ null, %9 ], [ %25, %22 ], [ %18, %19 ]
ret i8* %27
}