#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 */
struct pqos_cpuinfo {
  int dummy;
};
struct pqos_cap {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ _pqos_api_lock();
int /*<<< orphan*/ _pqos_api_unlock();
int /*<<< orphan*/ _pqos_cap_get(struct pqos_cap const **,
                                 struct pqos_cpuinfo const **);
int _pqos_check_init(int);
int pqos_cap_get(const struct pqos_cap **cap, const struct pqos_cpuinfo **cpu) {
  int ret = 0;
  if (cap == NULL && cpu == NULL)
    return 2;
  _pqos_api_lock();
  ret = _pqos_check_init(1);
  if (ret != 0) {
    _pqos_api_unlock();
    return ret;
  }
  _pqos_cap_get(cap, cpu);
  _pqos_api_unlock();
  return 0;
}


x86 assembly (clang, -O0):
<pqos_cap_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1179 <pqos_cap_get+0x39>
cmpq   $0x0,-0x18(%rbp)
jne    1179 <pqos_cap_get+0x39>
movl   $0x2,-0x4(%rbp)
jmp    11c4 <pqos_cap_get+0x84>
mov    $0x0,%al
call   1040 <_pqos_api_lock@plt>
mov    $0x1,%edi
call   1050 <_pqos_check_init@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11a9 <pqos_cap_get+0x69>
mov    $0x0,%al
call   1030 <_pqos_api_unlock@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <pqos_cap_get+0x84>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <_pqos_cap_get@plt>
mov    $0x0,%al
call   1030 <_pqos_api_unlock@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pqos_cap_get>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1159 <pqos_cap_get+0x19>
mov    $0x2,%ebp
test   %r14,%r14
je     1184 <pqos_cap_get+0x44>
xor    %eax,%eax
call   1040 <_pqos_api_lock@plt>
mov    $0x1,%edi
call   1050 <_pqos_check_init@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    117d <pqos_cap_get+0x3d>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <_pqos_cap_get@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <_pqos_api_unlock@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.pqos_cap = type { i32 }
%struct.pqos_cpuinfo = type { i32 }
define i32 @pqos_cap_get(%struct.pqos_cap** %0, %struct.pqos_cpuinfo** %1) {
%3 = alloca i32
%4 = alloca %struct.pqos_cap**
%5 = alloca %struct.pqos_cpuinfo**
%6 = alloca i32
store %struct.pqos_cap** %0, %struct.pqos_cap*** %4
store %struct.pqos_cpuinfo** %1, %struct.pqos_cpuinfo*** %5
store i32 0, i32* %6
%7 = load %struct.pqos_cap**, %struct.pqos_cap*** %4
%8 = icmp eq %struct.pqos_cap** %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load %struct.pqos_cpuinfo**, %struct.pqos_cpuinfo*** %5
%11 = icmp eq %struct.pqos_cpuinfo** %10, null
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 2, i32* %3
br label %26
13: ; preds = %9, %2
%14 = call i32 (...) @_pqos_api_lock()
%15 = call i32 @_pqos_check_init(i32 1)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = call i32 (...) @_pqos_api_unlock()
%20 = load i32, i32* %6
store i32 %20, i32* %3
br label %26
21: ; preds = %13
%22 = load %struct.pqos_cap**, %struct.pqos_cap*** %4
%23 = load %struct.pqos_cpuinfo**, %struct.pqos_cpuinfo*** %5
%24 = call i32 @_pqos_cap_get(%struct.pqos_cap** %22, %struct.pqos_cpuinfo** %23)
%25 = call i32 (...) @_pqos_api_unlock()
store i32 0, i32* %3
br label %26
26: ; preds = %21, %18, %12
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.pqos_cap = type { i32 }
%struct.pqos_cpuinfo = type { i32 }
define i32 @pqos_cap_get(%struct.pqos_cap** %0, %struct.pqos_cpuinfo** %1) {
%3 = icmp eq %struct.pqos_cap** %0, null
%4 = icmp eq %struct.pqos_cpuinfo** %1, null
%5 = and i1 %3, %4
br i1 %5, label %15, label %6
6: ; preds = %2
%7 = tail call i32 (...) @_pqos_api_lock()
%8 = tail call i32 @_pqos_check_init(i32 1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @_pqos_cap_get(%struct.pqos_cap** %0, %struct.pqos_cpuinfo** %1)
br label %12
12: ; preds = %6, %10
%13 = phi i32 [ 0, %10 ], [ %8, %6 ]
%14 = tail call i32 (...) @_pqos_api_unlock()
br label %15
15: ; preds = %12, %2
%16 = phi i32 [ 2, %2 ], [ %13, %12 ]
ret i32 %16
}