#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 *malloc(int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int html_cvt_malloc_string(const char *data, int len, void *dst,
                           void *closure) {
  if (data) {
    char *tmp = malloc(len + 1);
    if (tmp) {
      char **d = dst;
      strncpy(tmp, data, len);
      tmp[len] = '\0';
      *d = tmp;
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<html_cvt_malloc_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119c <html_cvt_malloc_string+0x7c>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1197 <html_cvt_malloc_string+0x77>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11a3 <html_cvt_malloc_string+0x83>
jmp    119c <html_cvt_malloc_string+0x7c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<html_cvt_malloc_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r12d,%r12d
test   %rdi,%rdi
je     1169 <html_cvt_malloc_string+0x49>
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0x1(%r15),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1169 <html_cvt_malloc_string+0x49>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
movslq %r15d,%rax
movb   $0x0,0x0(%rbp,%rax,1)
mov    %rbp,(%r14)
mov    $0x1,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @html_cvt_malloc_string(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8**
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %34
14: ; preds = %4
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 1
%17 = call i8* @malloc(i32 %16)
store i8* %17, i8** %10
%18 = load i8*, i8** %10
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %33
20: ; preds = %14
%21 = load i8*, i8** %8
%22 = bitcast i8* %21 to i8**
store i8** %22, i8*** %11
%23 = load i8*, i8** %10
%24 = load i8*, i8** %6
%25 = load i32, i32* %7
%26 = call i32 @strncpy(i8* %23, i8* %24, i32 %25)
%27 = load i8*, i8** %10
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
%31 = load i8*, i8** %10
%32 = load i8**, i8*** %11
store i8* %31, i8** %32
store i32 1, i32* %5
br label %35
33: ; preds = %14
br label %34
34: ; preds = %33, %4
store i32 0, i32* %5
br label %35
35: ; preds = %34, %20
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
define i32 @html_cvt_malloc_string(i8* %0, i32 %1, i8* nocapture writeonly %2, i8* nocapture readnone %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %15, label %6
6: ; preds = %4
%7 = add nsw i32 %1, 1
%8 = tail call i8* @malloc(i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = bitcast i8* %2 to i8**
%12 = tail call i32 @strncpy(i8* %8, i8* %0, i32 %1)
%13 = sext i32 %1 to i64
%14 = getelementptr inbounds i8, i8* %8, i64 %13
store i8 0, i8* %14
store i8* %8, i8** %11
br label %15
15: ; preds = %6, %4, %10
%16 = phi i32 [ 1, %10 ], [ 0, %4 ], [ 0, %6 ]
ret i32 %16
}