#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 code2unit(int);
char *bmap2statestr(unsigned int onmap, unsigned int dimmap,
                    unsigned int chgmap, unsigned int addrmap) {
  int j;
  int val;
  unsigned int bmap;
  static char outbuf[17];
  char hexdigit[] = "0123456789abcdef";
  for (j = 0; j < 16; j++) {
    val = 0;
    bmap = 1 << j;
    val += (onmap & bmap) ? 8 : 0;
    val += (dimmap & bmap) ? 4 : 0;
    val += (chgmap & bmap) ? 2 : 0;
    val += (addrmap & bmap) ? 1 : 0;
    outbuf[code2unit(j) - 1] = hexdigit[val];
  }
  outbuf[16] = '\0';
  return outbuf;
}


x86 assembly (clang, -O0):
<bmap2statestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    0xed5(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed2(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xed0(%rip),%al
mov    %al,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    1200 <bmap2statestr+0xf0>
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edx
and    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    $0x8,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edx
and    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    $0x4,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edx
and    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    $0x2,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%edx
and    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
mov    -0x30(%rbp,%rax,1),%al
mov    %al,-0x31(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <code2unit@plt>
mov    -0x31(%rbp),%dl
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e51(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114a <bmap2statestr+0x3a>
movb   $0x0,0x2e49(%rip)
lea    0x2e32(%rip),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bmap2statestr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%r12d
mov    %edi,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
bt     %ebx,%ebp
setb   %al
xor    %edx,%edx
bt     %ebx,%r12d
setb   %dl
xor    %esi,%esi
bt     %ebx,%r15d
setb   %sil
mov    %r14d,%edi
mov    %ebx,%ecx
shr    %cl,%edi
and    $0x1,%edi
lea    (%rdi,%rdx,4),%ecx
lea    (%rcx,%rax,8),%eax
lea    (%rax,%rsi,2),%eax
lea    0xe9b(%rip),%rcx
movzbl (%rax,%rcx,1),%r13d
mov    %ebx,%edi
call   1030 <code2unit@plt>
cltq
lea    0x2ec6(%rip),%rcx
mov    %r13b,-0x1(%rax,%rcx,1)
add    $0x1,%ebx
cmp    $0x10,%ebx
jne    1130 <bmap2statestr+0x20>
movb   $0x0,0x2ec2(%rip)
lea    0x2eab(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@bmap2statestr.outbuf = internal global [17 x i8] zeroinitializer
@__const.bmap2statestr.hexdigit = [17 x i8] c"0123456789abcdef\00"
define i8* @bmap2statestr(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [17 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = bitcast [17 x i8]* %12 to i8*
store i32 0, i32* %9
br label %14
14: ; preds = %61, %4
%15 = load i32, i32* %9
%16 = icmp slt i32 %15, 16
br i1 %16, label %17, label %64
17: ; preds = %14
store i32 0, i32* %10
%18 = load i32, i32* %9
%19 = shl i32 1, %18
store i32 %19, i32* %11
%20 = load i32, i32* %5
%21 = load i32, i32* %11
%22 = and i32 %20, %21
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 8, i32 0
%26 = load i32, i32* %10
%27 = add nsw i32 %26, %25
store i32 %27, i32* %10
%28 = load i32, i32* %6
%29 = load i32, i32* %11
%30 = and i32 %28, %29
%31 = icmp ne i32 %30, 0
%32 = zext i1 %31 to i64
%33 = select i1 %31, i32 4, i32 0
%34 = load i32, i32* %10
%35 = add nsw i32 %34, %33
store i32 %35, i32* %10
%36 = load i32, i32* %7
%37 = load i32, i32* %11
%38 = and i32 %36, %37
%39 = icmp ne i32 %38, 0
%40 = zext i1 %39 to i64
%41 = select i1 %39, i32 2, i32 0
%42 = load i32, i32* %10
%43 = add nsw i32 %42, %41
store i32 %43, i32* %10
%44 = load i32, i32* %8
%45 = load i32, i32* %11
%46 = and i32 %44, %45
%47 = icmp ne i32 %46, 0
%48 = zext i1 %47 to i64
%49 = select i1 %47, i32 1, i32 0
%50 = load i32, i32* %10
%51 = add nsw i32 %50, %49
store i32 %51, i32* %10
%52 = load i32, i32* %10
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [17 x i8], [17 x i8]* %12, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = load i32, i32* %9
%57 = call i32 @code2unit(i32 %56)
%58 = sub nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [17 x i8], [17 x i8]* @bmap2statestr.outbuf, i64 0, i64 %59
store i8 %55, i8* %60
br label %61
61: ; preds = %17
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
store i32 %63, i32* %9
br label %14
64: ; preds = %14
store i8 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @bmap2statestr.outbuf, i64 0, i64 16)
ret i8* getelementptr inbounds ([17 x i8], [17 x i8]* @bmap2statestr.outbuf, i64 0, i64 0)
}

LLVM IR (-O2):
@bmap2statestr.outbuf = internal global [17 x i8] zeroinitializer
@__const.bmap2statestr.hexdigit = [17 x i8] c"0123456789abcdef\00"
define i8* @bmap2statestr(i32 %0, i32 %1, i32 %2, i32 %3) {
br label %5
5: ; preds = %4, %5
%6 = phi i32 [ 0, %4 ], [ %29, %5 ]
%7 = shl nuw nsw i32 1, %6
%8 = and i32 %7, %0
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i32 0, i32 8
%11 = and i32 %7, %1
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 0, i32 4
%14 = and i32 %7, %2
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i32 0, i32 2
%17 = lshr i32 %3, %6
%18 = and i32 %17, 1
%19 = or i32 %13, %18
%20 = or i32 %19, %10
%21 = or i32 %20, %16
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.bmap2statestr.hexdigit, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = tail call i32 @code2unit(i32 %6)
%26 = add nsw i32 %25, -1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [17 x i8], [17 x i8]* @bmap2statestr.outbuf, i64 0, i64 %27
store i8 %24, i8* %28
%29 = add nuw nsw i32 %6, 1
%30 = icmp eq i32 %29, 16
br i1 %30, label %31, label %5
31: ; preds = %5
store i8 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @bmap2statestr.outbuf, i64 0, i64 16)
ret i8* getelementptr inbounds ([17 x i8], [17 x i8]* @bmap2statestr.outbuf, i64 0, i64 0)
}