#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_5__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ X509_ALGOR;
struct TYPE_5__ {
  int /*<<< orphan*/ salt;
  int /*<<< orphan*/ iter;
};
typedef TYPE_1__ PBEPARAM;
typedef int /*<<< orphan*/ ASN1_STRING;

/* Variables and functions */
int /*<<< orphan*/ ASN1_INTEGER_set(int /*<<< orphan*/, int);
unsigned char *ASN1_STRING_data(int /*<<< orphan*/);
int /*<<< orphan*/ ASN1_STRING_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ ASN1_STRING_set(int /*<<< orphan*/, int /*<<< orphan*/ *,
                                   int);
int /*<<< orphan*/ ASN1_item_pack(TYPE_1__ *, int /*<<< orphan*/ *,
                                  int /*<<< orphan*/ **);
int /*<<< orphan*/ ASN1error(int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ OBJ_nid2obj(int);
int /*<<< orphan*/ PBEPARAM_free(TYPE_1__ *);
int /*<<< orphan*/ PBEPARAM_it;
TYPE_1__ *PBEPARAM_new();
int PKCS5_DEFAULT_ITER;
int PKCS5_SALT_LEN;
int /*<<< orphan*/ V_ASN1_SEQUENCE;
scalar_t__ X509_ALGOR_set0(int /*<<< orphan*/ *, int /*<<< orphan*/,
                           int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ arc4random_buf(unsigned char *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
                         const unsigned char *salt, int saltlen) {
  PBEPARAM *pbe = NULL;
  ASN1_STRING *pbe_str = NULL;
  unsigned char *sstr;
  pbe = PBEPARAM_new();
  if (!pbe) {
    ASN1error(ERR_R_MALLOC_FAILURE);
    goto err;
  }
  if (iter <= 0)
    iter = PKCS5_DEFAULT_ITER;
  if (!ASN1_INTEGER_set(pbe->iter, iter)) {
    ASN1error(ERR_R_MALLOC_FAILURE);
    goto err;
  }
  if (!saltlen)
    saltlen = PKCS5_SALT_LEN;
  if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) {
    ASN1error(ERR_R_MALLOC_FAILURE);
    goto err;
  }
  sstr = ASN1_STRING_data(pbe->salt);
  if (salt)
    memcpy(sstr, salt, saltlen);
  else
    arc4random_buf(sstr, saltlen);
  if (!ASN1_item_pack(pbe, &PBEPARAM_it, &pbe_str)) {
    ASN1error(ERR_R_MALLOC_FAILURE);
    goto err;
  }
  PBEPARAM_free(pbe);
  pbe = NULL;
  if (X509_ALGOR_set0(algor, OBJ_nid2obj(alg), V_ASN1_SEQUENCE, pbe_str))
    return 1;
err:
  if (pbe != NULL)
    PBEPARAM_free(pbe);
  ASN1_STRING_free(pbe_str);
  return 0;
}


x86 assembly (clang, -O0):
<PKCS5_pbe_set0_algor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    $0x0,%al
call   1090 <PBEPARAM_new@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1213 <PKCS5_pbe_set0_algor+0x53>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   10e0 <ASN1error@plt>
jmp    1357 <PKCS5_pbe_set0_algor+0x197>
cmpl   $0x0,-0x18(%rbp)
jg     1229 <PKCS5_pbe_set0_algor+0x69>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x18(%rbp),%esi
call   10b0 <ASN1_INTEGER_set@plt>
cmp    $0x0,%eax
jne    1254 <PKCS5_pbe_set0_algor+0x94>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   10e0 <ASN1error@plt>
jmp    1357 <PKCS5_pbe_set0_algor+0x197>
cmpl   $0x0,-0x24(%rbp)
jne    126a <PKCS5_pbe_set0_algor+0xaa>
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10d0 <ASN1_STRING_set@plt>
cmp    $0x0,%eax
jne    1298 <PKCS5_pbe_set0_algor+0xd8>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   10e0 <ASN1error@plt>
jmp    1357 <PKCS5_pbe_set0_algor+0x197>
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
call   1070 <ASN1_STRING_data@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12c7 <PKCS5_pbe_set0_algor+0x107>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   10c0 <memcpy@plt>
jmp    12d3 <PKCS5_pbe_set0_algor+0x113>
mov    -0x40(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <arc4random_buf@plt>
mov    -0x30(%rbp),%rdi
mov    0x2d0a(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1030 <ASN1_item_pack@plt>
cmp    $0x0,%eax
jne    1303 <PKCS5_pbe_set0_algor+0x143>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
call   10e0 <ASN1error@plt>
jmp    1357 <PKCS5_pbe_set0_algor+0x197>
mov    -0x30(%rbp),%rdi
call   10a0 <PBEPARAM_free@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <OBJ_nid2obj@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
mov    0x2c87(%rip),%rax
mov    (%rax),%edx
mov    -0x38(%rbp),%rcx
call   1060 <X509_ALGOR_set0@plt>
cmp    $0x0,%rax
je     1352 <PKCS5_pbe_set0_algor+0x192>
movl   $0x1,-0x4(%rbp)
jmp    137b <PKCS5_pbe_set0_algor+0x1bb>
jmp    1357 <PKCS5_pbe_set0_algor+0x197>
cmpq   $0x0,-0x30(%rbp)
je     136b <PKCS5_pbe_set0_algor+0x1ab>
mov    -0x30(%rbp),%rdi
call   10a0 <PBEPARAM_free@plt>
mov    -0x38(%rbp),%rdi
call   1080 <ASN1_STRING_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PKCS5_pbe_set0_algor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r13d
mov    %rcx,%r12
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%r14
movq   $0x0,(%rsp)
xor    %eax,%eax
call   1090 <PBEPARAM_new@plt>
test   %rax,%rax
je     124e <PKCS5_pbe_set0_algor+0x8e>
mov    %rax,%rbx
test   %ebp,%ebp
jg     11fd <PKCS5_pbe_set0_algor+0x3d>
mov    0x2dcd(%rip),%rax
mov    (%rax),%ebp
mov    0x4(%rbx),%edi
mov    %ebp,%esi
call   10b0 <ASN1_INTEGER_set@plt>
test   %eax,%eax
je     12b2 <PKCS5_pbe_set0_algor+0xf2>
test   %r13d,%r13d
jne    121e <PKCS5_pbe_set0_algor+0x5e>
mov    0x2dbd(%rip),%rax
mov    (%rax),%r13d
mov    (%rbx),%edi
xor    %esi,%esi
mov    %r13d,%edx
call   10d0 <ASN1_STRING_set@plt>
test   %eax,%eax
je     12b2 <PKCS5_pbe_set0_algor+0xf2>
mov    (%rbx),%edi
call   1070 <ASN1_STRING_data@plt>
mov    %rax,%rdi
test   %r12,%r12
je     125e <PKCS5_pbe_set0_algor+0x9e>
mov    %r12,%rsi
mov    %r13d,%edx
call   10c0 <memcpy@plt>
jmp    1266 <PKCS5_pbe_set0_algor+0xa6>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   10e0 <ASN1error@plt>
jmp    12c8 <PKCS5_pbe_set0_algor+0x108>
mov    %r13d,%esi
call   1050 <arc4random_buf@plt>
mov    0x2d7b(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1030 <ASN1_item_pack@plt>
test   %eax,%eax
je     12b2 <PKCS5_pbe_set0_algor+0xf2>
mov    %rbx,%rdi
call   10a0 <PBEPARAM_free@plt>
mov    %r15d,%edi
call   1040 <OBJ_nid2obj@plt>
mov    0x2d25(%rip),%rcx
mov    (%rcx),%edx
mov    (%rsp),%rcx
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <X509_ALGOR_set0@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    12d3 <PKCS5_pbe_set0_algor+0x113>
jmp    12c8 <PKCS5_pbe_set0_algor+0x108>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
call   10e0 <ASN1error@plt>
mov    %rbx,%rdi
call   10a0 <PBEPARAM_free@plt>
mov    (%rsp),%rdi
call   1080 <ASN1_STRING_free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, i32 }
@ERR_R_MALLOC_FAILURE = global i32 0
@PKCS5_DEFAULT_ITER = global i32 0
@PKCS5_SALT_LEN = global i32 0
@PBEPARAM_it = global i32 0
@V_ASN1_SEQUENCE = global i32 0
define i32 @PKCS5_pbe_set0_algor(i32* %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca %struct.TYPE_5__*
%13 = alloca i32*
%14 = alloca i8*
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store %struct.TYPE_5__* null, %struct.TYPE_5__** %12
store i32* null, i32** %13
%15 = call %struct.TYPE_5__* (...) @PBEPARAM_new()
store %struct.TYPE_5__* %15, %struct.TYPE_5__** %12
%16 = load %struct.TYPE_5__*, %struct.TYPE_5__** %12
%17 = icmp ne %struct.TYPE_5__* %16, null
br i1 %17, label %21, label %18
18: ; preds = %5
%19 = load i32, i32* @ERR_R_MALLOC_FAILURE
%20 = call i32 @ASN1error(i32 %19)
br label %86
21: ; preds = %5
%22 = load i32, i32* %9
%23 = icmp sle i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = load i32, i32* @PKCS5_DEFAULT_ITER
store i32 %25, i32* %9
br label %26
26: ; preds = %24, %21
%27 = load %struct.TYPE_5__*, %struct.TYPE_5__** %12
%28 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = load i32, i32* %9
%31 = call i32 @ASN1_INTEGER_set(i32 %29, i32 %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %26
%34 = load i32, i32* @ERR_R_MALLOC_FAILURE
%35 = call i32 @ASN1error(i32 %34)
br label %86
36: ; preds = %26
%37 = load i32, i32* %11
%38 = icmp ne i32 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %36
%40 = load i32, i32* @PKCS5_SALT_LEN
store i32 %40, i32* %11
br label %41
41: ; preds = %39, %36
%42 = load %struct.TYPE_5__*, %struct.TYPE_5__** %12
%43 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = load i32, i32* %11
%46 = call i32 @ASN1_STRING_set(i32 %44, i32* null, i32 %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %41
%49 = load i32, i32* @ERR_R_MALLOC_FAILURE
%50 = call i32 @ASN1error(i32 %49)
br label %86
51: ; preds = %41
%52 = load %struct.TYPE_5__*, %struct.TYPE_5__** %12
%53 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = call i8* @ASN1_STRING_data(i32 %54)
store i8* %55, i8** %14
%56 = load i8*, i8** %10
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %63
58: ; preds = %51
%59 = load i8*, i8** %14
%60 = load i8*, i8** %10
%61 = load i32, i32* %11
%62 = call i32 @memcpy(i8* %59, i8* %60, i32 %61)
br label %67
63: ; preds = %51
%64 = load i8*, i8** %14
%65 = load i32, i32* %11
%66 = call i32 @arc4random_buf(i8* %64, i32 %65)
br label %67
67: ; preds = %63, %58
%68 = load %struct.TYPE_5__*, %struct.TYPE_5__** %12
%69 = call i32 @ASN1_item_pack(%struct.TYPE_5__* %68, i32* @PBEPARAM_it, i32** %13)
%70 = icmp ne i32 %69, 0
br i1 %70, label %74, label %71
71: ; preds = %67
%72 = load i32, i32* @ERR_R_MALLOC_FAILURE
%73 = call i32 @ASN1error(i32 %72)
br label %86
74: ; preds = %67
%75 = load %struct.TYPE_5__*, %struct.TYPE_5__** %12
%76 = call i32 @PBEPARAM_free(%struct.TYPE_5__* %75)
store %struct.TYPE_5__* null, %struct.TYPE_5__** %12
%77 = load i32*, i32** %7
%78 = load i32, i32* %8
%79 = call i32 @OBJ_nid2obj(i32 %78)
%80 = load i32, i32* @V_ASN1_SEQUENCE
%81 = load i32*, i32** %13
%82 = call i64 @X509_ALGOR_set0(i32* %77, i32 %79, i32 %80, i32* %81)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %74
store i32 1, i32* %6
br label %95
85: ; preds = %74
br label %86
86: ; preds = %85, %71, %48, %33, %18
%87 = load %struct.TYPE_5__*, %struct.TYPE_5__** %12
%88 = icmp ne %struct.TYPE_5__* %87, null
br i1 %88, label %89, label %92
89: ; preds = %86
%90 = load %struct.TYPE_5__*, %struct.TYPE_5__** %12
%91 = call i32 @PBEPARAM_free(%struct.TYPE_5__* %90)
br label %92
92: ; preds = %89, %86
%93 = load i32*, i32** %13
%94 = call i32 @ASN1_STRING_free(i32* %93)
store i32 0, i32* %6
br label %95
95: ; preds = %92, %84
%96 = load i32, i32* %6
ret i32 %96
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i32 }
@ERR_R_MALLOC_FAILURE = global i32 0
@PKCS5_DEFAULT_ITER = global i32 0
@PKCS5_SALT_LEN = global i32 0
@PBEPARAM_it = global i32 0
@V_ASN1_SEQUENCE = global i32 0
define i32 @PKCS5_pbe_set0_algor(i32* %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32*
%7 = bitcast i32** %6 to i8*
store i32* null, i32** %6
%8 = tail call %struct.TYPE_5__* (...) @PBEPARAM_new()
%9 = icmp eq %struct.TYPE_5__* %8, null
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i32, i32* @ERR_R_MALLOC_FAILURE
%12 = tail call i32 @ASN1error(i32 %11)
br label %58
13: ; preds = %5
%14 = icmp slt i32 %2, 1
%15 = load i32, i32* @PKCS5_DEFAULT_ITER
%16 = select i1 %14, i32 %15, i32 %2
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i64 0, i32 1
%18 = load i32, i32* %17
%19 = tail call i32 @ASN1_INTEGER_set(i32 %18, i32 %16)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = load i32, i32* @ERR_R_MALLOC_FAILURE
%23 = tail call i32 @ASN1error(i32 %22)
br label %56
24: ; preds = %13
%25 = icmp eq i32 %4, 0
%26 = load i32, i32* @PKCS5_SALT_LEN
%27 = select i1 %25, i32 %26, i32 %4
%28 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i64 0, i32 0
%29 = load i32, i32* %28
%30 = tail call i32 @ASN1_STRING_set(i32 %29, i32* null, i32 %27)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = load i32, i32* @ERR_R_MALLOC_FAILURE
%34 = tail call i32 @ASN1error(i32 %33)
br label %56
35: ; preds = %24
%36 = load i32, i32* %28
%37 = tail call i8* @ASN1_STRING_data(i32 %36)
%38 = icmp eq i8* %3, null
br i1 %38, label %41, label %39
39: ; preds = %35
%40 = tail call i32 @memcpy(i8* %37, i8* %3, i32 %27)
br label %43
41: ; preds = %35
%42 = tail call i32 @arc4random_buf(i8* %37, i32 %27)
br label %43
43: ; preds = %41, %39
%44 = call i32 @ASN1_item_pack(%struct.TYPE_5__* %8, i32* @PBEPARAM_it, i32** %6)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* @ERR_R_MALLOC_FAILURE
%48 = call i32 @ASN1error(i32 %47)
br label %56
49: ; preds = %43
%50 = call i32 @PBEPARAM_free(%struct.TYPE_5__* %8)
%51 = call i32 @OBJ_nid2obj(i32 %1)
%52 = load i32, i32* @V_ASN1_SEQUENCE
%53 = load i32*, i32** %6
%54 = call i64 @X509_ALGOR_set0(i32* %0, i32 %51, i32 %52, i32* %53)
%55 = icmp eq i64 %54, 0
br i1 %55, label %58, label %61
56: ; preds = %46, %32, %21
%57 = call i32 @PBEPARAM_free(%struct.TYPE_5__* %8)
br label %58
58: ; preds = %10, %49, %56
%59 = load i32*, i32** %6
%60 = call i32 @ASN1_STRING_free(i32* %59)
br label %61
61: ; preds = %49, %58
%62 = phi i32 [ 0, %58 ], [ 1, %49 ]
ret i32 %62
}