#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();
scalar_t__ CRYPTO_THREAD_read_lock(int /*<<< orphan*/ *);
scalar_t__ CRYPTO_THREAD_unlock(int /*<<< orphan*/ *);
int /*<<< orphan*/ test_true(char *, int, char *, int);
int test_lock(void) {
  CRYPTO_RWLOCK *lock = CRYPTO_THREAD_lock_new();
  if (!test_true(
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/"
          "master/Src/OSF/OpenSSL-111/test/threadstest.c",
          86, "CRYPTO_THREAD_read_lock(lock)",
          (CRYPTO_THREAD_read_lock(lock)) != 0) ||
      !test_true(
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/"
          "master/Src/OSF/OpenSSL-111/test/threadstest.c",
          87, "CRYPTO_THREAD_unlock(lock)", (CRYPTO_THREAD_unlock(lock)) != 0))
    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   1050 <CRYPTO_THREAD_lock_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <CRYPTO_THREAD_read_lock@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%ecx
lea    0xe81(%rip),%rdi
mov    $0x56,%esi
lea    0xf24(%rip),%rdx
call   1030 <test_true@plt>
cmp    $0x0,%eax
je     11cf <test_lock+0x7f>
mov    -0x10(%rbp),%rdi
call   1070 <CRYPTO_THREAD_unlock@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%ecx
lea    0xe4b(%rip),%rdi
mov    $0x57,%esi
lea    0xf0c(%rip),%rdx
call   1030 <test_true@plt>
cmp    $0x0,%eax
jne    11db <test_lock+0x8b>
movl   $0x0,-0x4(%rbp)
jmp    11eb <test_lock+0x9b>
mov    -0x10(%rbp),%rdi
call   1060 <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   1050 <CRYPTO_THREAD_lock_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <CRYPTO_THREAD_read_lock@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    0xe8a(%rip),%rdi
lea    0xf32(%rip),%rdx
mov    $0x56,%esi
call   1030 <test_true@plt>
test   %eax,%eax
je     11c4 <test_lock+0x74>
mov    %rbx,%rdi
call   1070 <CRYPTO_THREAD_unlock@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    0xe5e(%rip),%rdi
lea    0xf24(%rip),%rdx
mov    $0x57,%esi
call   1030 <test_true@plt>
test   %eax,%eax
je     11c4 <test_lock+0x74>
mov    %rbx,%rdi
call   1060 <CRYPTO_THREAD_lock_free@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [175 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/master/Src/OSF/OpenSSL-111/test/threadstest.c\00"
@.str.1 = [30 x i8] c"CRYPTO_THREAD_read_lock(lock)\00"
@.str.2 = [27 x i8] c"CRYPTO_THREAD_unlock(lock)\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 i64 @CRYPTO_THREAD_read_lock(i32* %4)
%6 = icmp ne i64 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @test_true(i8* getelementptr inbounds ([175 x i8], [175 x i8]* @.str, i64 0, i64 0), i32 86, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = call i64 @CRYPTO_THREAD_unlock(i32* %11)
%13 = icmp ne i64 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @test_true(i8* getelementptr inbounds ([175 x i8], [175 x i8]* @.str, i64 0, i64 0), i32 87, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %10, %0
store i32 0, i32* %1
br label %21
18: ; preds = %10
%19 = load i32*, i32** %2
%20 = call i32 @CRYPTO_THREAD_lock_free(i32* %19)
store i32 1, i32* %1
br label %21
21: ; preds = %18, %17
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [175 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/master/Src/OSF/OpenSSL-111/test/threadstest.c\00"
@.str.1 = [30 x i8] c"CRYPTO_THREAD_read_lock(lock)\00"
@.str.2 = [27 x i8] c"CRYPTO_THREAD_unlock(lock)\00"
define i32 @test_lock() {
%1 = tail call i32* (...) @CRYPTO_THREAD_lock_new()
%2 = tail call i64 @CRYPTO_THREAD_read_lock(i32* %1)
%3 = icmp ne i64 %2, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @test_true(i8* getelementptr inbounds ([175 x i8], [175 x i8]* @.str, i64 0, i64 0), i32 86, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %0
%8 = tail call i64 @CRYPTO_THREAD_unlock(i32* %1)
%9 = icmp ne i64 %8, 0
%10 = zext i1 %9 to i32
%11 = tail call i32 @test_true(i8* getelementptr inbounds ([175 x i8], [175 x i8]* @.str, i64 0, i64 0), i32 87, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = tail call i32 @CRYPTO_THREAD_lock_free(i32* %1)
br label %15
15: ; preds = %0, %7, %13
%16 = phi i32 [ 1, %13 ], [ 0, %7 ], [ 0, %0 ]
ret i32 %16
}