#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 */
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
size_t strListBlockLength(char *);
char *strListCopyBlock(char *block) {
  char *p;
  size_t block_len;
  if ((block_len = strListBlockLength(block)) == 0)
    return (NULL);
  if ((p = (char *)malloc(block_len)) == NULL)
    return (NULL);
  memcpy(p, block, block_len);
  return (p);
}


x86 assembly (clang, -O0):
<strListCopyBlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strListBlockLength@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1160 <strListCopyBlock+0x30>
movq   $0x0,-0x8(%rbp)
jmp    119d <strListCopyBlock+0x6d>
mov    -0x20(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1184 <strListCopyBlock+0x54>
movq   $0x0,-0x8(%rbp)
jmp    119d <strListCopyBlock+0x6d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strListCopyBlock>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strListBlockLength@plt>
test   %rax,%rax
je     1165 <strListCopyBlock+0x35>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     1165 <strListCopyBlock+0x35>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
jmp    1168 <strListCopyBlock+0x38>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @strListCopyBlock(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 i64 @strListBlockLength(i8* %6)
store i64 %7, i64* %5
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* null, i8** %2
br label %22
10: ; preds = %1
%11 = load i64, i64* %5
%12 = call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %4
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %10
store i8* null, i8** %2
br label %22
16: ; preds = %10
%17 = load i8*, i8** %4
%18 = load i8*, i8** %3
%19 = load i64, i64* %5
%20 = call i32 @memcpy(i8* %17, i8* %18, i64 %19)
%21 = load i8*, i8** %4
store i8* %21, i8** %2
br label %22
22: ; preds = %16, %15, %9
%23 = load i8*, i8** %2
ret i8* %23
}

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