#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*/ free(char *);
char *malloc(size_t);
scalar_t__ memchr(char const *, char, size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
char *strdup(char const *);
size_t strlen(char const *);
int x509_param_set1_internal(char **pdest, size_t *pdestlen, const char *src,
                             size_t srclen, int nonul) {
  char *tmp;
  if (src == NULL)
    return 0;
  if (srclen == 0) {
    srclen = strlen(src);
    if (srclen == 0)
      return 0;
    if ((tmp = strdup(src)) == NULL)
      return 0;
  } else {
    if (nonul && memchr(src, '\0', srclen))
      return 0;
    if ((tmp = malloc(srclen)) == NULL)
      return 0;
    memcpy(tmp, src, srclen);
  }
  if (*pdest)
    free(*pdest);
  *pdest = tmp;
  if (pdestlen)
    *pdestlen = srclen;
  return 1;
}


x86 assembly (clang, -O0):
<x509_param_set1_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1193 <x509_param_set1_internal+0x33>
movl   $0x0,-0x4(%rbp)
jmp    128f <x509_param_set1_internal+0x12f>
cmpq   $0x0,-0x28(%rbp)
jne    11ea <x509_param_set1_internal+0x8a>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c2 <x509_param_set1_internal+0x62>
movl   $0x0,-0x4(%rbp)
jmp    128f <x509_param_set1_internal+0x12f>
mov    -0x20(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11e5 <x509_param_set1_internal+0x85>
movl   $0x0,-0x4(%rbp)
jmp    128f <x509_param_set1_internal+0x12f>
jmp    124d <x509_param_set1_internal+0xed>
cmpl   $0x0,-0x2c(%rbp)
je     1219 <x509_param_set1_internal+0xb9>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
xor    %esi,%esi
call   1050 <memchr@plt>
cmp    $0x0,%rax
je     1219 <x509_param_set1_internal+0xb9>
movl   $0x0,-0x4(%rbp)
jmp    128f <x509_param_set1_internal+0x12f>
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    123c <x509_param_set1_internal+0xdc>
movl   $0x0,-0x4(%rbp)
jmp    128f <x509_param_set1_internal+0x12f>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1267 <x509_param_set1_internal+0x107>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     1288 <x509_param_set1_internal+0x128>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<x509_param_set1_internal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdx,%rdx
je     1202 <x509_param_set1_internal+0xa2>
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
test   %rcx,%rcx
je     11c5 <x509_param_set1_internal+0x65>
test   %r8d,%r8d
je     11a0 <x509_param_set1_internal+0x40>
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1050 <memchr@plt>
test   %rax,%rax
jne    1202 <x509_param_set1_internal+0xa2>
mov    %r12,%rdi
call   1070 <malloc@plt>
mov    $0x0,%ebp
test   %rax,%rax
je     1202 <x509_param_set1_internal+0xa2>
mov    %rax,%r13
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1060 <memcpy@plt>
jmp    11e5 <x509_param_set1_internal+0x85>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     1202 <x509_param_set1_internal+0xa2>
mov    %rax,%r12
mov    %rbx,%rdi
call   1080 <strdup@plt>
test   %rax,%rax
je     1202 <x509_param_set1_internal+0xa2>
mov    %rax,%r13
mov    (%r15),%rdi
test   %rdi,%rdi
je     11f2 <x509_param_set1_internal+0x92>
call   1030 <free@plt>
mov    %r13,(%r15)
mov    $0x1,%ebp
test   %r14,%r14
je     1202 <x509_param_set1_internal+0xa2>
mov    %r12,(%r14)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @x509_param_set1_internal(i8** %0, i64* %1, i8* %2, i64 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i64*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i8*
store i8** %0, i8*** %7
store i64* %1, i64** %8
store i8* %2, i8** %9
store i64 %3, i64* %10
store i32 %4, i32* %11
%13 = load i8*, i8** %9
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %5
store i32 0, i32* %6
br label %67
16: ; preds = %5
%17 = load i64, i64* %10
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %16
%20 = load i8*, i8** %9
%21 = call i64 @strlen(i8* %20)
store i64 %21, i64* %10
%22 = load i64, i64* %10
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 0, i32* %6
br label %67
25: ; preds = %19
%26 = load i8*, i8** %9
%27 = call i8* @strdup(i8* %26)
store i8* %27, i8** %12
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 0, i32* %6
br label %67
30: ; preds = %25
br label %50
31: ; preds = %16
%32 = load i32, i32* %11
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load i8*, i8** %9
%36 = load i64, i64* %10
%37 = call i64 @memchr(i8* %35, i8 signext 0, i64 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %34
store i32 0, i32* %6
br label %67
40: ; preds = %34, %31
%41 = load i64, i64* %10
%42 = call i8* @malloc(i64 %41)
store i8* %42, i8** %12
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %45
44: ; preds = %40
store i32 0, i32* %6
br label %67
45: ; preds = %40
%46 = load i8*, i8** %12
%47 = load i8*, i8** %9
%48 = load i64, i64* %10
%49 = call i32 @memcpy(i8* %46, i8* %47, i64 %48)
br label %50
50: ; preds = %45, %30
%51 = load i8**, i8*** %7
%52 = load i8*, i8** %51
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = load i8**, i8*** %7
%56 = load i8*, i8** %55
%57 = call i32 @free(i8* %56)
br label %58
58: ; preds = %54, %50
%59 = load i8*, i8** %12
%60 = load i8**, i8*** %7
store i8* %59, i8** %60
%61 = load i64*, i64** %8
%62 = icmp ne i64* %61, null
br i1 %62, label %63, label %66
63: ; preds = %58
%64 = load i64, i64* %10
%65 = load i64*, i64** %8
store i64 %64, i64* %65
br label %66
66: ; preds = %63, %58
store i32 1, i32* %6
br label %67
67: ; preds = %66, %44, %39, %29, %24, %15
%68 = load i32, i32* %6
ret i32 %68
}

LLVM IR (-O2):
define i32 @x509_param_set1_internal(i8** nocapture %0, i64* writeonly %1, i8* %2, i64 %3, i32 %4) {
%6 = icmp eq i8* %2, null
br i1 %6, label %35, label %7
7: ; preds = %5
%8 = icmp eq i64 %3, 0
br i1 %8, label %9, label %15
9: ; preds = %7
%10 = tail call i64 @strlen(i8* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %35, label %12
12: ; preds = %9
%13 = tail call i8* @strdup(i8* %2)
%14 = icmp eq i8* %13, null
br i1 %14, label %35, label %25
15: ; preds = %7
%16 = icmp eq i32 %4, 0
br i1 %16, label %20, label %17
17: ; preds = %15
%18 = tail call i64 @memchr(i8* %2, i8 signext 0, i64 %3)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %35
20: ; preds = %17, %15
%21 = tail call i8* @malloc(i64 %3)
%22 = icmp eq i8* %21, null
br i1 %22, label %35, label %23
23: ; preds = %20
%24 = tail call i32 @memcpy(i8* %21, i8* %2, i64 %3)
br label %25
25: ; preds = %12, %23
%26 = phi i64 [ %10, %12 ], [ %3, %23 ]
%27 = phi i8* [ %13, %12 ], [ %21, %23 ]
%28 = load i8*, i8** %0
%29 = icmp eq i8* %28, null
br i1 %29, label %32, label %30
30: ; preds = %25
%31 = tail call i32 @free(i8* %28)
br label %32
32: ; preds = %30, %25
store i8* %27, i8** %0
%33 = icmp eq i64* %1, null
br i1 %33, label %35, label %34
34: ; preds = %32
store i64 %26, i64* %1
br label %35
35: ; preds = %32, %34, %20, %17, %12, %9, %5
%36 = phi i32 [ 0, %5 ], [ 0, %9 ], [ 0, %12 ], [ 0, %17 ], [ 0, %20 ], [ 1, %34 ], [ 1, %32 ]
ret i32 %36
}