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

/* Variables and functions */
scalar_t__ counter_entry(unsigned long *);
int /*<<< orphan*/ pthread_mutex_lock(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_mutex_unlock(int /*<<< orphan*/ *);
void fake_set_bit(int nr, unsigned long *addr) {
  unsigned long mask = (1UL << ((nr) % 32));
  unsigned long *p = ((unsigned long *)counter_entry(addr)) + ((nr) / 32);
  pthread_mutex_t *lock = (pthread_mutex_t *)addr;
  pthread_mutex_lock(lock);
  *p |= mask;
  pthread_mutex_unlock(lock);
}


x86 assembly (clang, -O0):
<fake_set_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <counter_entry@plt>
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <pthread_mutex_lock@plt>
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
or     (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <pthread_mutex_unlock@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fake_set_bit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ecx
lea    0x1f(%rcx),%ebp
test   %edi,%edi
cmovns %edi,%ebp
mov    %ebp,%eax
and    $0xffffffe0,%eax
sub    %eax,%ecx
mov    $0x1,%ebx
shl    %cl,%rbx
mov    %rsi,%rdi
call   1040 <counter_entry@plt>
mov    %rax,%r14
sar    $0x5,%ebp
movslq %ebp,%rbp
mov    %r15,%rdi
call   1050 <pthread_mutex_lock@plt>
or     %rbx,(%r14,%rbp,8)
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <pthread_mutex_unlock@plt>

LLVM IR (-O0):
define void @fake_set_bit(i32 %0, i64* %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i64
%6 = alloca i64*
%7 = alloca i32*
store i32 %0, i32* %3
store i64* %1, i64** %4
%8 = load i32, i32* %3
%9 = srem i32 %8, 32
%10 = zext i32 %9 to i64
%11 = shl i64 1, %10
store i64 %11, i64* %5
%12 = load i64*, i64** %4
%13 = call i64 @counter_entry(i64* %12)
%14 = inttoptr i64 %13 to i64*
%15 = load i32, i32* %3
%16 = sdiv i32 %15, 32
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i64, i64* %14, i64 %17
store i64* %18, i64** %6
%19 = load i64*, i64** %4
%20 = bitcast i64* %19 to i32*
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = call i32 @pthread_mutex_lock(i32* %21)
%23 = load i64, i64* %5
%24 = load i64*, i64** %6
%25 = load i64, i64* %24
%26 = or i64 %25, %23
store i64 %26, i64* %24
%27 = load i32*, i32** %7
%28 = call i32 @pthread_mutex_unlock(i32* %27)
ret void
}

LLVM IR (-O2):
define void @fake_set_bit(i32 %0, i64* %1) {
%3 = srem i32 %0, 32
%4 = zext i32 %3 to i64
%5 = shl nuw i64 1, %4
%6 = tail call i64 @counter_entry(i64* %1)
%7 = inttoptr i64 %6 to i64*
%8 = sdiv i32 %0, 32
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i64, i64* %7, i64 %9
%11 = bitcast i64* %1 to i32*
%12 = tail call i32 @pthread_mutex_lock(i32* %11)
%13 = load i64, i64* %10
%14 = or i64 %13, %5
store i64 %14, i64* %10
%15 = tail call i32 @pthread_mutex_unlock(i32* %11)
ret void
}