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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *, int, int *);
int getpid();
int /*<<< orphan*/ stderr;
void done_read_lock(int *lk) {
  ;
  ;
  if (*lk <= 0) {
    fprintf(stderr, "sync.c: pid=%d   %s    %d at %p   UNBALANCED\n", getpid(),
            "done_read_lock", *lk, lk);
    *lk = 1;
  }
  *lk = *lk - 1;
  ;
  ;
}


x86 assembly (clang, -O0):
<done_read_lock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jg     1179 <done_read_lock+0x59>
mov    0x2ea0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0xc(%rbp),%edi
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%r8d
mov    -0x8(%rbp),%r9
lea    0xe9d(%rip),%rsi
lea    0xec4(%rip),%rcx
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<done_read_lock>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%eax
test   %eax,%eax
jg     115e <done_read_lock+0x3e>
mov    0x2ead(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    (%rbx),%r8d
lea    0xeba(%rip),%rsi
lea    0xee1(%rip),%rcx
mov    %ebp,%edi
mov    %eax,%edx
mov    %rbx,%r9
call   1040 <fprintf@plt>
mov    $0x1,%eax
add    $0xffffffff,%eax
mov    %eax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [46 x i8] c"sync.c: pid=%d %s %d at %p UNBALANCED\0A\00"
@.str.1 = [15 x i8] c"done_read_lock\00"
define void @done_read_lock(i32* %0) {
%2 = alloca i32*
store i32* %0, i32** %2
%3 = load i32*, i32** %2
%4 = load i32, i32* %3
%5 = icmp sle i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 (...) @getpid()
%9 = load i32*, i32** %2
%10 = load i32, i32* %9
%11 = load i32*, i32** %2
%12 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32* %11)
%13 = load i32*, i32** %2
store i32 1, i32* %13
br label %14
14: ; preds = %6, %1
%15 = load i32*, i32** %2
%16 = load i32, i32* %15
%17 = sub nsw i32 %16, 1
%18 = load i32*, i32** %2
store i32 %17, i32* %18
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [46 x i8] c"sync.c: pid=%d %s %d at %p UNBALANCED\0A\00"
@.str.1 = [15 x i8] c"done_read_lock\00"
define void @done_read_lock(i32* %0) {
%2 = load i32, i32* %0
%3 = icmp slt i32 %2, 1
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 (...) @getpid()
%7 = load i32, i32* %0
%8 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32* %0)
br label %9
9: ; preds = %4, %1
%10 = phi i32 [ 1, %4 ], [ %2, %1 ]
%11 = add nsw i32 %10, -1
store i32 %11, i32* %0
ret void
}