#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 *CRYPTO_malloc(scalar_t__, char const *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *CRYPTO_strdup(const char *str, const char *file, int line) {
  char *ret;
  if (str == NULL)
    return NULL;
  ret = CRYPTO_malloc(strlen(str) + 1, file, line);
  if (ret != NULL)
    strcpy(ret, str);
  return ret;
}


x86 assembly (clang, -O0):
<CRYPTO_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115b <CRYPTO_strdup+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    119b <CRYPTO_strdup+0x6b>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <CRYPTO_malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1193 <CRYPTO_strdup+0x63>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CRYPTO_strdup>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     1169 <CRYPTO_strdup+0x39>
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <CRYPTO_malloc@plt>
test   %rax,%rax
je     1169 <CRYPTO_strdup+0x39>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    116b <CRYPTO_strdup+0x3b>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @CRYPTO_strdup(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %3
store i8* null, i8** %4
br label %27
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %14, 1
%16 = load i8*, i8** %6
%17 = load i32, i32* %7
%18 = call i8* @CRYPTO_malloc(i64 %15, i8* %16, i32 %17)
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %12
%22 = load i8*, i8** %8
%23 = load i8*, i8** %5
%24 = call i32 @strcpy(i8* %22, i8* %23)
br label %25
25: ; preds = %21, %12
%26 = load i8*, i8** %8
store i8* %26, i8** %4
br label %27
27: ; preds = %25, %11
%28 = load i8*, i8** %4
ret i8* %28
}

LLVM IR (-O2):
define i8* @CRYPTO_strdup(i8* %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %12, label %5
5: ; preds = %3
%6 = tail call i64 @strlen(i8* %0)
%7 = add nsw i64 %6, 1
%8 = tail call i8* @CRYPTO_malloc(i64 %7, i8* %1, i32 %2)
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %5
%11 = tail call i32 @strcpy(i8* %8, i8* %0)
br label %12
12: ; preds = %5, %10, %3
%13 = phi i8* [ null, %3 ], [ %8, %10 ], [ null, %5 ]
ret i8* %13
}