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

/* Variables and functions */
#define LOCK_EX 130
int LOCK_NB;
#define LOCK_SH 129
#define LOCK_UN 128
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strlcat(char *, char *, int);
int /*<<< orphan*/ strlcpy(char *, char *, int);
const char *lock2name(int l) {
  static char buf[1024];
  int nb = l & LOCK_NB;
  l &= ~LOCK_NB;
  if (nb)
    strlcpy(buf, "LOCK_NB|", sizeof(buf));
  else
    buf[0] = '\0';
  switch (l) {
  case LOCK_SH:
    strlcat(buf, "LOCK_SH", sizeof(buf));
    return buf;
  case LOCK_EX:
    strlcat(buf, "LOCK_EX", sizeof(buf));
    return buf;
  case LOCK_UN:
    strlcat(buf, "LOCK_UN", sizeof(buf));
    return buf;
  default:
    snprintf(buf, sizeof(buf), "*%d*", l | nb);
    return buf;
  }
}


x86 assembly (clang, -O0):
<lock2name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e93(%rip),%rcx
and    (%rcx),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1183 <lock2name+0x53>
lea    0x2ee3(%rip),%rdi
lea    0xe8c(%rip),%rsi
mov    $0x400,%edx
call   1050 <strlcpy@plt>
jmp    118a <lock2name+0x5a>
movb   $0x0,0x2ec6(%rip)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x80,%eax
je     1216 <lock2name+0xe6>
jmp    11a0 <lock2name+0x70>
mov    -0x14(%rbp),%eax
sub    $0x81,%eax
je     11c6 <lock2name+0x96>
jmp    11b3 <lock2name+0x83>
mov    -0x14(%rbp),%eax
sub    $0x82,%eax
je     11ee <lock2name+0xbe>
jmp    123e <lock2name+0x10e>
lea    0x2e83(%rip),%rdi
lea    0xe35(%rip),%rsi
mov    $0x400,%edx
call   1030 <strlcat@plt>
lea    0x2e6b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1267 <lock2name+0x137>
lea    0x2e5b(%rip),%rdi
lea    0xe15(%rip),%rsi
mov    $0x400,%edx
call   1030 <strlcat@plt>
lea    0x2e43(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1267 <lock2name+0x137>
lea    0x2e33(%rip),%rdi
lea    0xdf5(%rip),%rsi
mov    $0x400,%edx
call   1030 <strlcat@plt>
lea    0x2e1b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1267 <lock2name+0x137>
mov    -0xc(%rbp),%ecx
or     -0x10(%rbp),%ecx
lea    0x2e05(%rip),%rdi
mov    $0x400,%esi
lea    0xdca(%rip),%rdx
call   1040 <snprintf@plt>
lea    0x2ded(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lock2name>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2e9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ebp
not    %ebp
and    %edi,%ebp
test   %edi,%eax
je     1162 <lock2name+0x32>
lea    0x2f01(%rip),%rdi
lea    0xeaa(%rip),%rsi
mov    $0x400,%edx
call   1050 <strlcpy@plt>
jmp    1169 <lock2name+0x39>
movb   $0x0,0x2ee7(%rip)
lea    0x2ee0(%rip),%rdi
cmp    $0x80,%ebp
je     1191 <lock2name+0x61>
cmp    $0x82,%ebp
je     119a <lock2name+0x6a>
cmp    $0x81,%ebp
jne    11ad <lock2name+0x7d>
lea    0xe7a(%rip),%rsi
jmp    11a1 <lock2name+0x71>
lea    0xe81(%rip),%rsi
jmp    11a1 <lock2name+0x71>
lea    0xe70(%rip),%rsi
mov    $0x400,%edx
call   1030 <strlcat@plt>
jmp    11c0 <lock2name+0x90>
lea    0xe6d(%rip),%rdx
mov    $0x400,%esi
mov    %ebx,%ecx
call   1040 <snprintf@plt>
lea    0x2e89(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@lock2name.buf = internal global [1024 x i8] zeroinitializer
@LOCK_NB = global i32 0
@.str = [9 x i8] c"LOCK_NB|\00"
@.str.1 = [8 x i8] c"LOCK_SH\00"
@.str.2 = [8 x i8] c"LOCK_EX\00"
@.str.3 = [8 x i8] c"LOCK_UN\00"
@.str.4 = [5 x i8] c"*%d*\00"
define i8* @lock2name(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = load i32, i32* @LOCK_NB
%7 = and i32 %5, %6
store i32 %7, i32* %4
%8 = load i32, i32* @LOCK_NB
%9 = xor i32 %8, -1
%10 = load i32, i32* %3
%11 = and i32 %10, %9
store i32 %11, i32* %3
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @strlcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 1024)
br label %17
16: ; preds = %1
store i8 0, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0)
br label %17
17: ; preds = %16, %14
%18 = load i32, i32* %3
switch i32 %18, label %25 [
i32 129, label %19
i32 130, label %21
i32 128, label %23
]
19: ; preds = %17
%20 = call i32 @strlcat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1024)
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0), i8** %2
br label %30
21: ; preds = %17
%22 = call i32 @strlcat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 1024)
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0), i8** %2
br label %30
23: ; preds = %17
%24 = call i32 @strlcat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 1024)
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0), i8** %2
br label %30
25: ; preds = %17
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = or i32 %26, %27
%29 = call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %28)
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0), i8** %2
br label %30
30: ; preds = %25, %23, %21, %19
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
@lock2name.buf = internal global [1024 x i8] zeroinitializer
@LOCK_NB = global i32 0
@.str = [9 x i8] c"LOCK_NB|\00"
@.str.1 = [8 x i8] c"LOCK_SH\00"
@.str.2 = [8 x i8] c"LOCK_EX\00"
@.str.3 = [8 x i8] c"LOCK_UN\00"
@.str.4 = [5 x i8] c"*%d*\00"
define i8* @lock2name(i32 %0) {
%2 = load i32, i32* @LOCK_NB
%3 = and i32 %2, %0
%4 = xor i32 %2, -1
%5 = and i32 %4, %0
%6 = icmp eq i32 %3, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 @strlcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 1024)
br label %10
9: ; preds = %1
store i8 0, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0)
br label %10
10: ; preds = %9, %7
switch i32 %5, label %17 [
i32 129, label %11
i32 130, label %13
i32 128, label %15
]
11: ; preds = %10
%12 = tail call i32 @strlcat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1024)
br label %19
13: ; preds = %10
%14 = tail call i32 @strlcat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 1024)
br label %19
15: ; preds = %10
%16 = tail call i32 @strlcat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 1024)
br label %19
17: ; preds = %10
%18 = tail call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %0)
br label %19
19: ; preds = %17, %15, %13, %11
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lock2name.buf, i64 0, i64 0)
}