#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 O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int lock();
int open(char *, int, ...);
int /*<<< orphan*/ read(int, unsigned int *, int);
int /*<<< orphan*/ unlock(int);
int /*<<< orphan*/ write(int, unsigned int *, int);
void dec_lock_count() {
  int lock_id = lock();
  unsigned count = 0;
  int fd = open("lock_count", O_RDONLY);
  if (fd != -1)
    read(fd, &count, sizeof(unsigned));
  close(fd);
  count--;
  fd = open("lock_count", O_WRONLY | O_CREAT, 0666);
  if (fd != -1)
    write(fd, &count, sizeof(unsigned));
  close(fd);
  unlock(lock_id);
}


x86 assembly (clang, -O0):
<dec_lock_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <lock@plt>
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     11ae <dec_lock_count+0x4e>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
mov    0x2e29(%rip),%rax
or     (%rax),%esi
lea    0xe28(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     1202 <dec_lock_count+0xa2>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1050 <write@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%edi
call   1030 <unlock@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec_lock_count>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1040 <lock@plt>
mov    %eax,%r14d
movl   $0x0,0xc(%rsp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
lea    0xe76(%rip),%rdi
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     11b2 <dec_lock_count+0x52>
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1070 <read@plt>
mov    0xc(%rsp),%ebx
add    $0xffffffff,%ebx
jmp    11b7 <dec_lock_count+0x57>
mov    $0xffffffff,%ebx
mov    %ebp,%edi
call   1060 <close@plt>
mov    %ebx,0xc(%rsp)
mov    0x2dff(%rip),%rax
mov    0x2e28(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe25(%rip),%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     11ff <dec_lock_count+0x9f>
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1050 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r14d,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <unlock@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"lock_count\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define void @dec_lock_count() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (...) @lock()
store i32 %4, i32* %1
store i32 0, i32* %2
%5 = load i32, i32* @O_RDONLY
%6 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i32, i32* %3
%11 = call i32 @read(i32 %10, i32* %2, i32 4)
br label %12
12: ; preds = %9, %0
%13 = load i32, i32* %3
%14 = call i32 @close(i32 %13)
%15 = load i32, i32* %2
%16 = add i32 %15, -1
store i32 %16, i32* %2
%17 = load i32, i32* @O_WRONLY
%18 = load i32, i32* @O_CREAT
%19 = or i32 %17, %18
%20 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %19, i32 438)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %12
%24 = load i32, i32* %3
%25 = call i32 @write(i32 %24, i32* %2, i32 4)
br label %26
26: ; preds = %23, %12
%27 = load i32, i32* %3
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %1
%30 = call i32 @unlock(i32 %29)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"lock_count\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define void @dec_lock_count() {
%1 = alloca i32
%2 = tail call i32 (...) @lock()
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %11, label %7
7: ; preds = %0
%8 = call i32 @read(i32 %5, i32* %1, i32 4)
%9 = load i32, i32* %1
%10 = add i32 %9, -1
br label %11
11: ; preds = %7, %0
%12 = phi i32 [ %10, %7 ], [ -1, %0 ]
%13 = tail call i32 @close(i32 %5)
store i32 %12, i32* %1
%14 = load i32, i32* @O_WRONLY
%15 = load i32, i32* @O_CREAT
%16 = or i32 %15, %14
%17 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %16, i32 438)
%18 = icmp eq i32 %17, -1
br i1 %18, label %21, label %19
19: ; preds = %11
%20 = call i32 @write(i32 %17, i32* %1, i32 4)
br label %21
21: ; preds = %19, %11
%22 = tail call i32 @close(i32 %17)
%23 = tail call i32 @unlock(i32 %2)
ret void
}