#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*/ *gethostbyname(char const *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int strlen(char const *);
char *config_parse_host(const char *buf) {
  char *new_host;
  size_t len;
  if (gethostbyname(buf) == NULL) {
    return NULL;
  }
  len = strlen(buf) + 1;
  new_host = malloc(sizeof(char) * len);
  memcpy(new_host, buf, len);
  return new_host;
}


x86 assembly (clang, -O0):
<config_parse_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
cmp    $0x0,%rax
jne    116c <config_parse_host+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    11aa <config_parse_host+0x6a>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_parse_host>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     117b <config_parse_host+0x3b>
mov    %r14,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
movslq %eax,%r15
mov    %r15d,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
jmp    117d <config_parse_host+0x3d>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @config_parse_host(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @gethostbyname(i8* %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* null, i8** %2
br label %24
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 1
%14 = sext i32 %13 to i64
store i64 %14, i64* %5
%15 = load i64, i64* %5
%16 = mul i64 1, %15
%17 = trunc i64 %16 to i32
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %4
%19 = load i8*, i8** %4
%20 = load i8*, i8** %3
%21 = load i64, i64* %5
%22 = call i32 @memcpy(i8* %19, i8* %20, i64 %21)
%23 = load i8*, i8** %4
store i8* %23, i8** %2
br label %24
24: ; preds = %10, %9
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
define i8* @config_parse_host(i8* %0) {
%2 = tail call i32* @gethostbyname(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, 1
%7 = sext i32 %6 to i64
%8 = tail call i8* @malloc(i32 %6)
%9 = tail call i32 @memcpy(i8* %8, i8* %0, i64 %7)
br label %10
10: ; preds = %1, %4
%11 = phi i8* [ %8, %4 ], [ null, %1 ]
ret i8* %11
}