#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ byte_copy(char *, unsigned int, char const *);
unsigned int dns_domain_length(char const *);
int dns_domain_copy(char **out, const char *in) {
  char *x = NULL;
  unsigned int len = 0;
  assert(in != NULL);
  assert(out != NULL);
  len = dns_domain_length(in);
  if (!(x = alloc(len)))
    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)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1030 <dns_domain_length@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <alloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11c1 <dns_domain_copy+0x71>
movl   $0x0,-0x4(%rbp)
jmp    11fd <dns_domain_copy+0xad>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1070 <byte_copy@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     11eb <dns_domain_copy+0x9b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <alloc_free@plt>
mov    -0x20(%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
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <assert@plt>
mov    %r15,%rdi
call   1030 <dns_domain_length@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <alloc@plt>
test   %rax,%rax
je     11b6 <dns_domain_copy+0x66>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
call   1070 <byte_copy@plt>
mov    (%r14),%rdi
test   %rdi,%rdi
je     11ac <dns_domain_copy+0x5c>
call   1050 <alloc_free@plt>
mov    %rbx,(%r14)
mov    $0x1,%eax
jmp    11b8 <dns_domain_copy+0x68>
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 i8*
%7 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i8* null, i8** %6
store i32 0, i32* %7
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8**, i8*** %4
%13 = icmp ne i8** %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %5
%17 = call i32 @dns_domain_length(i8* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = call i8* @alloc(i32 %18)
store i8* %19, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %2
store i32 0, i32* %3
br label %37
22: ; preds = %2
%23 = load i8*, i8** %6
%24 = load i32, i32* %7
%25 = load i8*, i8** %5
%26 = call i32 @byte_copy(i8* %23, i32 %24, i8* %25)
%27 = load i8**, i8*** %4
%28 = load i8*, i8** %27
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %34
30: ; preds = %22
%31 = load i8**, i8*** %4
%32 = load i8*, i8** %31
%33 = call i32 @alloc_free(i8* %32)
br label %34
34: ; preds = %30, %22
%35 = load i8*, i8** %6
%36 = load i8**, i8*** %4
store i8* %35, i8** %36
store i32 1, i32* %3
br label %37
37: ; preds = %34, %21
%38 = load i32, i32* %3
ret i32 %38
}

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