#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int length;
  int /*<<< orphan*/ data;
};
typedef TYPE_1__ ASN1_IA5STRING;

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, int);
char *ssl_ia5string_strdup(ASN1_IA5STRING *ia5) {
  char *str;
  if (!ia5 || !ia5->length)
    return NULL;
  str = malloc(ia5->length + 1);
  if (!str)
    return NULL;
  memcpy(str, ia5->data, ia5->length);
  str[ia5->length] = 0;
  return str;
}


x86 assembly (clang, -O0):
<ssl_ia5string_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1144 <ssl_ia5string_strdup+0x24>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1151 <ssl_ia5string_strdup+0x31>
movq   $0x0,-0x8(%rbp)
jmp    11a8 <ssl_ia5string_strdup+0x88>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117b <ssl_ia5string_strdup+0x5b>
movq   $0x0,-0x8(%rbp)
jmp    11a8 <ssl_ia5string_strdup+0x88>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_ia5string_strdup>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     115e <ssl_ia5string_strdup+0x3e>
mov    %rdi,%rbx
mov    (%rdi),%r15d
test   %r15d,%r15d
je     115e <ssl_ia5string_strdup+0x3e>
lea    0x1(%r15),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     115e <ssl_ia5string_strdup+0x3e>
mov    %rax,%r14
mov    0x4(%rbx),%esi
mov    %rax,%rdi
mov    %r15d,%edx
call   1030 <memcpy@plt>
movslq (%rbx),%rax
movb   $0x0,(%r14,%rax,1)
jmp    1161 <ssl_ia5string_strdup+0x41>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
define i8* @ssl_ia5string_strdup(%struct.TYPE_3__* %0) {
%2 = icmp eq %struct.TYPE_3__* %0, null
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 0
br i1 %6, label %18, label %7
7: ; preds = %3
%8 = add nsw i32 %5, 1
%9 = tail call i8* @malloc(i32 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %7
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 1
%13 = load i32, i32* %12
%14 = tail call i32 @memcpy(i8* %9, i32 %13, i32 %5)
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %9, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %7, %1, %3, %11
%19 = phi i8* [ %9, %11 ], [ null, %3 ], [ null, %1 ], [ null, %7 ]
ret i8* %19
}