#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*/ sprintf(char *, char *, int);
char *hmask(int bits) {
  static char buf[20];
  if (bits < 32) {
    sprintf(buf, "0x%x", (1 << bits) - 1);
  } else if (bits == 32) {
    return "0xffffffff";
  } else if (bits == 64) {
    return "0xffffffffffffffff";
  } else {
    sprintf(buf, "0x%xffffffff", (1 << (bits - 32)) - 1);
  }
  return buf;
}


x86 assembly (clang, -O0):
<hmask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x20,-0xc(%rbp)
jge    114a <hmask+0x3a>
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
sub    $0x1,%edx
lea    0x2f07(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11ab <hmask+0x9b>
cmpl   $0x20,-0xc(%rbp)
jne    1164 <hmask+0x54>
lea    0xeaa(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b6 <hmask+0xa6>
cmpl   $0x40,-0xc(%rbp)
jne    117e <hmask+0x6e>
lea    0xe9b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b6 <hmask+0xa6>
mov    -0xc(%rbp),%ecx
sub    $0x20,%ecx
mov    $0x1,%edx
shl    %cl,%edx
sub    $0x1,%edx
lea    0x2eab(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11a6 <hmask+0x96>
jmp    11ab <hmask+0x9b>
lea    0x2e8e(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hmask>:
push   %rbx
cmp    $0x1f,%edi
jg     1131 <hmask+0x21>
mov    $0xffffffff,%edx
mov    %edi,%ecx
shl    %cl,%edx
not    %edx
lea    0x2f18(%rip),%rbx
lea    0xed1(%rip),%rsi
jmp    1166 <hmask+0x56>
cmp    $0x20,%edi
je     1144 <hmask+0x34>
cmp    $0x40,%edi
jne    114d <hmask+0x3d>
lea    0xece(%rip),%rbx
jmp    116e <hmask+0x5e>
lea    0xeba(%rip),%rbx
jmp    116e <hmask+0x5e>
mov    $0xffffffff,%edx
mov    %edi,%ecx
shl    %cl,%edx
not    %edx
lea    0x2ee1(%rip),%rbx
lea    0xebd(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@hmask.buf = internal global [20 x i8] zeroinitializer
@.str = [5 x i8] c"0x%x\00"
@.str.1 = [11 x i8] c"0xffffffff\00"
@.str.2 = [19 x i8] c"0xffffffffffffffff\00"
@.str.3 = [13 x i8] c"0x%xffffffff\00"
define i8* @hmask(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 32
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* %3
%8 = shl i32 1, %7
%9 = sub nsw i32 %8, 1
%10 = call i32 @sprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @hmask.buf, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %27
11: ; preds = %1
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 32
br i1 %13, label %14, label %15
14: ; preds = %11
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %28
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 64
br i1 %17, label %18, label %19
18: ; preds = %15
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %28
19: ; preds = %15
%20 = load i32, i32* %3
%21 = sub nsw i32 %20, 32
%22 = shl i32 1, %21
%23 = sub nsw i32 %22, 1
%24 = call i32 @sprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @hmask.buf, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %19
br label %26
26: ; preds = %25
br label %27
27: ; preds = %26, %6
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @hmask.buf, i64 0, i64 0), i8** %2
br label %28
28: ; preds = %27, %18, %14
%29 = load i8*, i8** %2
ret i8* %29
}

LLVM IR (-O2):
@hmask.buf = internal global [20 x i8] zeroinitializer
@.str = [5 x i8] c"0x%x\00"
@.str.1 = [11 x i8] c"0xffffffff\00"
@.str.2 = [19 x i8] c"0xffffffffffffffff\00"
@.str.3 = [13 x i8] c"0x%xffffffff\00"
define i8* @hmask(i32 %0) {
%2 = icmp slt i32 %0, 32
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = shl nsw i32 -1, %0
%5 = xor i32 %4, -1
%6 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @hmask.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %14
7: ; preds = %1
switch i32 %0, label %9 [
i32 32, label %14
i32 64, label %8
]
8: ; preds = %7
br label %14
9: ; preds = %7
%10 = add nsw i32 %0, -32
%11 = shl nsw i32 -1, %10
%12 = xor i32 %11, -1
%13 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @hmask.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %3, %9, %7, %8
%15 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %8 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %7 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @hmask.buf, i64 0, i64 0), %9 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @hmask.buf, i64 0, i64 0), %3 ]
ret i8* %15
}