#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*/ html_armor_text(unsigned char const *, int, unsigned char *);
int html_armored_memlen(unsigned char const *, int);
int strlen(unsigned char const *);
scalar_t__ xmalloc(int);
unsigned char *html_armor_string_dup(const unsigned char *str) {
  int inlen;
  int outlen;
  unsigned char *buf;
  if (!str)
    str = "";
  inlen = strlen(str);
  outlen = html_armored_memlen(str, inlen);
  buf = (unsigned char *)xmalloc(outlen + 1);
  html_armor_text(str, inlen, buf);
  return buf;
}


x86 assembly (clang, -O0):
<html_armor_string_dup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1162 <html_armor_string_dup+0x22>
lea    0xea2(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <html_armored_memlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
add    $0x1,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1060 <html_armor_text@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<html_armor_string_dup>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
lea    0xeaf(%rip),%rax
cmove  %rax,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <html_armored_memlen@plt>
lea    0x1(%rax),%edi
call   1040 <xmalloc@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rax,%rdx
call   1060 <html_armor_text@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @html_armor_string_dup(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
br label %9
9: ; preds = %8, %1
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %3
%12 = load i8*, i8** %2
%13 = load i32, i32* %3
%14 = call i32 @html_armored_memlen(i8* %12, i32 %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
%17 = call i64 @xmalloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %5
%19 = load i8*, i8** %2
%20 = load i32, i32* %3
%21 = load i8*, i8** %5
%22 = call i32 @html_armor_text(i8* %19, i32 %20, i8* %21)
%23 = load i8*, i8** %5
ret i8* %23
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @html_armor_string_dup(i8* %0) {
%2 = icmp eq i8* %0, null
%3 = select i1 %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
%4 = tail call i32 @strlen(i8* %3)
%5 = tail call i32 @html_armored_memlen(i8* %3, i32 %4)
%6 = add nsw i32 %5, 1
%7 = tail call i64 @xmalloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @html_armor_text(i8* %3, i32 %4, i8* %8)
ret i8* %8
}