#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 */
char *alloc(unsigned int);
int /*<<< orphan*/ alloc_free(char *);
int /*<<< orphan*/ byte_copy(char *, unsigned int, char *);
unsigned int dns_domain_length(char *);
int dns_domain_copy(char **out, char *in) {
  unsigned int len;
  char *x;
  len = dns_domain_length(in);
  x = alloc(len);
  if (!x)
    return 0;
  byte_copy(x, len, in);
  if (*out)
    alloc_free(*out);
  *out = x;
  return 1;
}


x86 assembly (clang, -O0):
<dns_domain_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <dns_domain_length@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <alloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117f <dns_domain_copy+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    11bb <dns_domain_copy+0x7b>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1060 <byte_copy@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     11a9 <dns_domain_copy+0x69>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <alloc_free@plt>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dns_domain_copy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <dns_domain_length@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <alloc@plt>
test   %rax,%rax
je     118a <dns_domain_copy+0x4a>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
call   1060 <byte_copy@plt>
mov    (%r14),%rdi
test   %rdi,%rdi
je     1180 <dns_domain_copy+0x40>
call   1040 <alloc_free@plt>
mov    %rbx,(%r14)
mov    $0x1,%eax
jmp    118c <dns_domain_copy+0x4c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @dns_domain_copy(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @dns_domain_length(i8* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = call i8* @alloc(i32 %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i32 0, i32* %3
br label %30
15: ; preds = %2
%16 = load i8*, i8** %7
%17 = load i32, i32* %6
%18 = load i8*, i8** %5
%19 = call i32 @byte_copy(i8* %16, i32 %17, i8* %18)
%20 = load i8**, i8*** %4
%21 = load i8*, i8** %20
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %15
%24 = load i8**, i8*** %4
%25 = load i8*, i8** %24
%26 = call i32 @alloc_free(i8* %25)
br label %27
27: ; preds = %23, %15
%28 = load i8*, i8** %7
%29 = load i8**, i8*** %4
store i8* %28, i8** %29
store i32 1, i32* %3
br label %30
30: ; preds = %27, %14
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
define i32 @dns_domain_copy(i8** nocapture %0, i8* %1) {
%3 = tail call i32 @dns_domain_length(i8* %1)
%4 = tail call i8* @alloc(i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = tail call i32 @byte_copy(i8* %4, i32 %3, i8* %1)
%8 = load i8*, i8** %0
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @alloc_free(i8* %8)
br label %12
12: ; preds = %10, %6
store i8* %4, i8** %0
br label %13
13: ; preds = %2, %12
%14 = phi i32 [ 1, %12 ], [ 0, %2 ]
ret i32 %14
}