#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*/ CRYPTO_RWLOCK;

/* Variables and functions */
int /*<<< orphan*/ CRYPTO_THREAD_lock_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *CRYPTO_THREAD_lock_new();
int /*<<< orphan*/ CRYPTO_THREAD_read_lock(int /*<<< orphan*/ *);
int /*<<< orphan*/ CRYPTO_THREAD_unlock(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int test_lock(void) {
  CRYPTO_RWLOCK *lock = CRYPTO_THREAD_lock_new();
  if (!CRYPTO_THREAD_read_lock(lock)) {
    fprintf(stderr, "CRYPTO_THREAD_read_lock() failed\n");
    return 0;
  }
  if (!CRYPTO_THREAD_unlock(lock)) {
    fprintf(stderr, "CRYPTO_THREAD_unlock() failed\n");
    return 0;
  }
  CRYPTO_THREAD_lock_free(lock);
  return 1;
}


x86 assembly (clang, -O0):
<test_lock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <CRYPTO_THREAD_lock_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <CRYPTO_THREAD_read_lock@plt>
cmp    $0x0,%eax
jne    1196 <test_lock+0x46>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <test_lock+0x89>
mov    -0x10(%rbp),%rdi
call   1070 <CRYPTO_THREAD_unlock@plt>
cmp    $0x0,%eax
jne    11c9 <test_lock+0x79>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <test_lock+0x89>
mov    -0x10(%rbp),%rdi
call   1050 <CRYPTO_THREAD_lock_free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_lock>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <CRYPTO_THREAD_lock_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <CRYPTO_THREAD_read_lock@plt>
test   %eax,%eax
je     1186 <test_lock+0x36>
mov    %rbx,%rdi
call   1070 <CRYPTO_THREAD_unlock@plt>
test   %eax,%eax
je     119d <test_lock+0x4d>
mov    %rbx,%rdi
call   1050 <CRYPTO_THREAD_lock_free@plt>
mov    $0x1,%ebp
jmp    11b4 <test_lock+0x64>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11b4 <test_lock+0x64>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
call   1060 <fprintf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"CRYPTO_THREAD_read_lock() failed\0A\00"
@.str.1 = [31 x i8] c"CRYPTO_THREAD_unlock() failed\0A\00"
define i32 @test_lock() {
%1 = alloca i32
%2 = alloca i32*
%3 = call i32* (...) @CRYPTO_THREAD_lock_new()
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = call i32 @CRYPTO_THREAD_read_lock(i32* %4)
%6 = icmp ne i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %20
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = call i32 @CRYPTO_THREAD_unlock(i32* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %20
17: ; preds = %10
%18 = load i32*, i32** %2
%19 = call i32 @CRYPTO_THREAD_lock_free(i32* %18)
store i32 1, i32* %1
br label %20
20: ; preds = %17, %14, %7
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"CRYPTO_THREAD_read_lock() failed\0A\00"
@.str.1 = [31 x i8] c"CRYPTO_THREAD_unlock() failed\0A\00"
define i32 @test_lock() {
%1 = tail call i32* (...) @CRYPTO_THREAD_lock_new()
%2 = tail call i32 @CRYPTO_THREAD_read_lock(i32* %1)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %15
7: ; preds = %0
%8 = tail call i32 @CRYPTO_THREAD_unlock(i32* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %15
13: ; preds = %7
%14 = tail call i32 @CRYPTO_THREAD_lock_free(i32* %1)
br label %15
15: ; preds = %13, %10, %4
%16 = phi i32 [ 1, %13 ], [ 0, %10 ], [ 0, %4 ]
ret i32 %16
}