#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 *);
int /*<<< orphan*/ getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
char *strdup(char *);
int strlen(char *);
char *_get_host_from_user(void) {
  size_t len = 0;
  char *host = NULL;
  printf("host: [www.mediafire.com] ");
  getline(&host, &len, stdin);
  if (host[strlen(host) - 1] == '\n')
    host[strlen(host) - 1] = '\0';
  if (host == NULL)
    return strdup("www.mediafire.com");
  if (strlen(host) < 2) {
    free(host);
    return strdup("www.mediafire.com");
  }
  return host;
}


x86 assembly (clang, -O0):
<_get_host_from_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe91(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <getline@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11d5 <_get_host_from_user+0x85>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpq   $0x0,-0x18(%rbp)
jne    11f5 <_get_host_from_user+0xa5>
lea    0xe34(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    122d <_get_host_from_user+0xdd>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jge    1225 <_get_host_from_user+0xd5>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe04(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    122d <_get_host_from_user+0xdd>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_get_host_from_user>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
lea    0xe93(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1060 <getline@plt>
mov    (%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11b0 <_get_host_from_user+0x60>
mov    (%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    (%rsp),%rdi
test   %rdi,%rdi
je     11d1 <_get_host_from_user+0x81>
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    (%rsp),%rax
cmp    $0x1,%ecx
jg     11dd <_get_host_from_user+0x8d>
mov    %rax,%rdi
call   1030 <free@plt>
lea    0xe43(%rip),%rdi
call   1070 <strdup@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"host: [www.mediafire.com] \00"
@stdin = global i32 0
@.str.1 = [18 x i8] c"www.mediafire.com\00"
define i8* @_get_host_from_user() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i8*
store i64 0, i64* %2
store i8* null, i8** %3
%4 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i32 @getline(i8** %3, i64* %2, i32 %5)
%7 = load i8*, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = sub nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %7, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 10
br i1 %15, label %16, label %23
16: ; preds = %0
%17 = load i8*, i8** %3
%18 = load i8*, i8** %3
%19 = call i32 @strlen(i8* %18)
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %17, i64 %21
store i8 0, i8* %22
br label %23
23: ; preds = %16, %0
%24 = load i8*, i8** %3
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i8* @strdup(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i8* %27, i8** %1
br label %38
28: ; preds = %23
%29 = load i8*, i8** %3
%30 = call i32 @strlen(i8* %29)
%31 = icmp slt i32 %30, 2
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i8*, i8** %3
%34 = call i32 @free(i8* %33)
%35 = call i8* @strdup(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i8* %35, i8** %1
br label %38
36: ; preds = %28
%37 = load i8*, i8** %3
store i8* %37, i8** %1
br label %38
38: ; preds = %36, %32, %26
%39 = load i8*, i8** %1
ret i8* %39
}

LLVM IR (-O2):
@.str = [27 x i8] c"host: [www.mediafire.com] \00"
@stdin = global i32 0
@.str.1 = [18 x i8] c"www.mediafire.com\00"
define i8* @_get_host_from_user() {
%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 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @getline(i8** %2, i64* %1, i32 %6)
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 10
br i1 %14, label %15, label %21
15: ; preds = %0
%16 = load i8*, i8** %2
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
store i8 0, i8* %20
br label %21
21: ; preds = %15, %0
%22 = load i8*, i8** %2
%23 = icmp eq i8* %22, null
br i1 %23, label %30, label %24
24: ; preds = %21
%25 = call i32 @strlen(i8* %22)
%26 = icmp slt i32 %25, 2
%27 = load i8*, i8** %2
br i1 %26, label %28, label %32
28: ; preds = %24
%29 = call i32 @free(i8* %27)
br label %30
30: ; preds = %21, %28
%31 = call dereferenceable_or_null(18) i8* @strdup(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %24
%33 = phi i8* [ %27, %24 ], [ %31, %30 ]
ret i8* %33
}