#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*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ OPENSSL_assert(int);
char *OPENSSL_strndup(char const *, size_t);
size_t OPENSSL_strnlen(char const *, size_t);
int /*<<< orphan*/ stderr;
char *dup_str(const unsigned char *in, size_t len) {
  char *ret;
  if (len == 0)
    return NULL;
  do {
    if (!(OPENSSL_strnlen((const char *)(in), len) == len)) {
      ERR_print_errors_fp(stderr);
      OPENSSL_assert(!"OPENSSL_strnlen((const char*)(in), len) == len");
    }
  } while (0);
  ;
  ret = OPENSSL_strndup((const char *)(in), len);
  do {
    if (!(ret != NULL)) {
      ERR_print_errors_fp(stderr);
      OPENSSL_assert(!"ret != NULL");
    }
  } while (0);
  ;
  return ret;
}


x86 assembly (clang, -O0):
<dup_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1168 <dup_str+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11dc <dup_str+0x9c>
jmp    116d <dup_str+0x2d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <OPENSSL_strnlen@plt>
cmp    -0x18(%rbp),%rax
je     1199 <dup_str+0x59>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1060 <ERR_print_errors_fp@plt>
xor    %edi,%edi
call   1050 <OPENSSL_assert@plt>
jmp    119e <dup_str+0x5e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <OPENSSL_strndup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cf <dup_str+0x8f>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1060 <ERR_print_errors_fp@plt>
xor    %edi,%edi
call   1050 <OPENSSL_assert@plt>
jmp    11d4 <dup_str+0x94>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dup_str>:
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     119a <dup_str+0x5a>
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <OPENSSL_strnlen@plt>
cmp    %rbx,%rax
je     116e <dup_str+0x2e>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
call   1060 <ERR_print_errors_fp@plt>
xor    %edi,%edi
call   1050 <OPENSSL_assert@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <OPENSSL_strndup@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119c <dup_str+0x5c>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1060 <ERR_print_errors_fp@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <OPENSSL_assert@plt>
jmp    119c <dup_str+0x5c>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [47 x i8] c"OPENSSL_strnlen((const char*)(in), len) == len\00"
@.str.1 = [12 x i8] c"ret != NULL\00"
define i8* @dup_str(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i64, i64* %5
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i8* null, i8** %3
br label %36
10: ; preds = %2
br label %11
11: ; preds = %10
%12 = load i8*, i8** %4
%13 = load i64, i64* %5
%14 = call i64 @OPENSSL_strnlen(i8* %12, i64 %13)
%15 = load i64, i64* %5
%16 = icmp eq i64 %14, %15
br i1 %16, label %21, label %17
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = call i32 @ERR_print_errors_fp(i32 %18)
%20 = call i32 @OPENSSL_assert(i32 0)
br label %21
21: ; preds = %17, %11
br label %22
22: ; preds = %21
%23 = load i8*, i8** %4
%24 = load i64, i64* %5
%25 = call i8* @OPENSSL_strndup(i8* %23, i64 %24)
store i8* %25, i8** %6
br label %26
26: ; preds = %22
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 @ERR_print_errors_fp(i32 %30)
%32 = call i32 @OPENSSL_assert(i32 0)
br label %33
33: ; preds = %29, %26
br label %34
34: ; preds = %33
%35 = load i8*, i8** %6
store i8* %35, i8** %3
br label %36
36: ; preds = %34, %9
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
@stderr = global i32 0
define i8* @dup_str(i8* %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %18, label %4
4: ; preds = %2
%5 = tail call i64 @OPENSSL_strnlen(i8* %0, i64 %1)
%6 = icmp eq i64 %5, %1
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @ERR_print_errors_fp(i32 %8)
%10 = tail call i32 @OPENSSL_assert(i32 0)
br label %11
11: ; preds = %7, %4
%12 = tail call i8* @OPENSSL_strndup(i8* %0, i64 %1)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i32 @ERR_print_errors_fp(i32 %15)
%17 = tail call i32 @OPENSSL_assert(i32 0)
br label %18
18: ; preds = %11, %14, %2
%19 = phi i8* [ null, %2 ], [ null, %14 ], [ %12, %11 ]
ret i8* %19
}