#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 */
typedef int /*<<< orphan*/ PKCS12;

/* Variables and functions */
int /*<<< orphan*/ PKCS12_R_INVALID_NULL_PKCS12_POINTER;
int /*<<< orphan*/ PKCS12_R_MAC_VERIFY_FAILURE;
int /*<<< orphan*/ PKCS12_R_PARSE_ERROR;
int /*<<< orphan*/ PKCS12_verify_mac(int /*<<< orphan*/ *, char const *, int);
int /*<<< orphan*/ PKCS12error(int /*<<< orphan*/);
int /*<<< orphan*/ newpass_p12(int /*<<< orphan*/ *, char const *,
                               char const *);
int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass) {
  if (!p12) {
    PKCS12error(PKCS12_R_INVALID_NULL_PKCS12_POINTER);
    return 0;
  }
  if (!PKCS12_verify_mac(p12, oldpass, -1)) {
    PKCS12error(PKCS12_R_MAC_VERIFY_FAILURE);
    return 0;
  }
  if (!newpass_p12(p12, oldpass, newpass)) {
    PKCS12error(PKCS12_R_PARSE_ERROR);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<PKCS12_newpass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1169 <PKCS12_newpass+0x39>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
call   1030 <PKCS12error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <PKCS12_newpass+0xa9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xffffffff,%edx
call   1040 <PKCS12_verify_mac@plt>
cmp    $0x0,%eax
jne    119e <PKCS12_newpass+0x6e>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1030 <PKCS12error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <PKCS12_newpass+0xa9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <newpass_p12@plt>
cmp    $0x0,%eax
jne    11d2 <PKCS12_newpass+0xa2>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1030 <PKCS12error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <PKCS12_newpass+0xa9>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PKCS12_newpass>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1173 <PKCS12_newpass+0x43>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0xffffffff,%edx
call   1040 <PKCS12_verify_mac@plt>
test   %eax,%eax
je     117c <PKCS12_newpass+0x4c>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <newpass_p12@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
jne    118c <PKCS12_newpass+0x5c>
mov    0x2e77(%rip),%rax
jmp    1183 <PKCS12_newpass+0x53>
mov    0x2e66(%rip),%rax
jmp    1183 <PKCS12_newpass+0x53>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1030 <PKCS12error@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@PKCS12_R_INVALID_NULL_PKCS12_POINTER = global i32 0
@PKCS12_R_MAC_VERIFY_FAILURE = global i32 0
@PKCS12_R_PARSE_ERROR = global i32 0
define i32 @PKCS12_newpass(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%8 = load i32*, i32** %5
%9 = icmp ne i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i32, i32* @PKCS12_R_INVALID_NULL_PKCS12_POINTER
%12 = call i32 @PKCS12error(i32 %11)
store i32 0, i32* %4
br label %31
13: ; preds = %3
%14 = load i32*, i32** %5
%15 = load i8*, i8** %6
%16 = call i32 @PKCS12_verify_mac(i32* %14, i8* %15, i32 -1)
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = load i32, i32* @PKCS12_R_MAC_VERIFY_FAILURE
%20 = call i32 @PKCS12error(i32 %19)
store i32 0, i32* %4
br label %31
21: ; preds = %13
%22 = load i32*, i32** %5
%23 = load i8*, i8** %6
%24 = load i8*, i8** %7
%25 = call i32 @newpass_p12(i32* %22, i8* %23, i8* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %21
%28 = load i32, i32* @PKCS12_R_PARSE_ERROR
%29 = call i32 @PKCS12error(i32 %28)
store i32 0, i32* %4
br label %31
30: ; preds = %21
store i32 1, i32* %4
br label %31
31: ; preds = %30, %27, %18, %10
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@PKCS12_R_INVALID_NULL_PKCS12_POINTER = global i32 0
@PKCS12_R_MAC_VERIFY_FAILURE = global i32 0
@PKCS12_R_PARSE_ERROR = global i32 0
define i32 @PKCS12_newpass(i32* %0, i8* %1, i8* %2) {
%4 = icmp eq i32* %0, null
br i1 %4, label %11, label %5
5: ; preds = %3
%6 = tail call i32 @PKCS12_verify_mac(i32* %0, i8* %1, i32 -1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i32 @newpass_p12(i32* %0, i8* %1, i8* %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8, %5, %3
%12 = phi i32* [ @PKCS12_R_INVALID_NULL_PKCS12_POINTER, %3 ], [ @PKCS12_R_MAC_VERIFY_FAILURE, %5 ], [ @PKCS12_R_PARSE_ERROR, %8 ]
%13 = load i32, i32* %12
%14 = tail call i32 @PKCS12error(i32 %13)
br label %15
15: ; preds = %11, %8
%16 = phi i32 [ 1, %8 ], [ 0, %11 ]
ret i32 %16
}