#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*/ X509_EXTENSION;
typedef int /*<<< orphan*/ OCSP_REQUEST;
typedef int /*<<< orphan*/ OCSP_BASICRESP;

/* Variables and functions */
int /*<<< orphan*/ NID_id_pkix_OCSP_Nonce;
int OCSP_BASICRESP_add_ext(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ *OCSP_REQUEST_get_ext(int /*<<< orphan*/ *, int);
int OCSP_REQUEST_get_ext_by_NID(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req) {
  X509_EXTENSION *req_ext;
  int req_idx;
  req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1);
  if (req_idx < 0)
    return 2;
  req_ext = OCSP_REQUEST_get_ext(req, req_idx);
  return OCSP_BASICRESP_add_ext(resp, req_ext, -1);
}


x86 assembly (clang, -O0):
<OCSP_copy_nonce>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2ea5(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edx
call   1030 <OCSP_REQUEST_get_ext_by_NID@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1170 <OCSP_copy_nonce+0x40>
movl   $0x2,-0x4(%rbp)
jmp    1195 <OCSP_copy_nonce+0x65>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <OCSP_REQUEST_get_ext@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0xffffffff,%edx
call   1040 <OCSP_BASICRESP_add_ext@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OCSP_copy_nonce>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2eaf(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
mov    $0xffffffff,%edx
call   1030 <OCSP_REQUEST_get_ext_by_NID@plt>
test   %eax,%eax
js     1175 <OCSP_copy_nonce+0x45>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <OCSP_REQUEST_get_ext@plt>
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0xffffffff,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <OCSP_BASICRESP_add_ext@plt>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@NID_id_pkix_OCSP_Nonce = global i32 0
define i32 @OCSP_copy_nonce(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %5
%9 = load i32, i32* @NID_id_pkix_OCSP_Nonce
%10 = call i32 @OCSP_REQUEST_get_ext_by_NID(i32* %8, i32 %9, i32 -1)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 2, i32* %3
br label %21
14: ; preds = %2
%15 = load i32*, i32** %5
%16 = load i32, i32* %7
%17 = call i32* @OCSP_REQUEST_get_ext(i32* %15, i32 %16)
store i32* %17, i32** %6
%18 = load i32*, i32** %4
%19 = load i32*, i32** %6
%20 = call i32 @OCSP_BASICRESP_add_ext(i32* %18, i32* %19, i32 -1)
store i32 %20, i32* %3
br label %21
21: ; preds = %14, %13
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@NID_id_pkix_OCSP_Nonce = global i32 0
define i32 @OCSP_copy_nonce(i32* %0, i32* %1) {
%3 = load i32, i32* @NID_id_pkix_OCSP_Nonce
%4 = tail call i32 @OCSP_REQUEST_get_ext_by_NID(i32* %1, i32 %3, i32 -1)
%5 = icmp slt i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32* @OCSP_REQUEST_get_ext(i32* %1, i32 %4)
%8 = tail call i32 @OCSP_BASICRESP_add_ext(i32* %0, i32* %7, i32 -1)
br label %9
9: ; preds = %2, %6
%10 = phi i32 [ %8, %6 ], [ 2, %2 ]
ret i32 %10
}