#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 /*<<< orphan*/ strlen(char *);
char *AddBitmapInfoString(char *outstring, int wh, int palnum, int mapofn) {
  int cellw = 0, cellh = 0;
  switch (wh) {
  case 0:
    cellw = 512;
    cellh = 256;
    break;
  case 1:
    cellw = 512;
    cellh = 512;
    break;
  case 2:
    cellw = 1024;
    cellh = 256;
    break;
  case 3:
    cellw = 1024;
    cellh = 512;
    break;
  }
  sprintf(outstring, "Bitmap(%dx%d)\r\n", cellw, cellh);
  outstring += strlen(outstring);
  if (palnum & 0x20) {
    sprintf(outstring, "Bitmap Special Priority enabled\r\n");
    outstring += strlen(outstring);
  }
  if (palnum & 0x10) {
    sprintf(outstring, "Bitmap Special Color Calculation enabled\r\n");
    outstring += strlen(outstring);
  }
  sprintf(outstring, "Bitmap Address = %X\r\n", (mapofn & 0x7) * 0x20000);
  outstring += strlen(outstring);
  sprintf(outstring, "Bitmap Palette Address = %X\r\n", (palnum & 0x7) << 4);
  outstring += strlen(outstring);
  return outstring;
}


x86 assembly (clang, -O0):
<AddBitmapInfoString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    %rax,-0x28(%rbp)
sub    $0x3,%rax
ja     11af <AddBitmapInfoString+0x8f>
mov    -0x28(%rbp),%rax
lea    0xea1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x200,-0x18(%rbp)
movl   $0x100,-0x1c(%rbp)
jmp    11af <AddBitmapInfoString+0x8f>
movl   $0x200,-0x18(%rbp)
movl   $0x200,-0x1c(%rbp)
jmp    11af <AddBitmapInfoString+0x8f>
movl   $0x400,-0x18(%rbp)
movl   $0x100,-0x1c(%rbp)
jmp    11af <AddBitmapInfoString+0x8f>
movl   $0x400,-0x18(%rbp)
movl   $0x200,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     121a <AddBitmapInfoString+0xfa>
mov    -0x8(%rbp),%rdi
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     1254 <AddBitmapInfoString+0x134>
mov    -0x8(%rbp),%rdi
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
and    $0x7,%edx
shl    $0x11,%edx
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
and    $0x7,%edx
shl    $0x4,%edx
lea    0xde7(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AddBitmapInfoString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rdi,%rbx
xor    %edx,%edx
mov    $0x0,%ecx
cmp    $0x3,%esi
ja     1153 <AddBitmapInfoString+0x33>
movslq %esi,%rax
lea    0xf4e(%rip),%rcx
mov    (%rcx,%rax,4),%edx
lea    0xf54(%rip),%rcx
mov    (%rcx,%rax,4),%ecx
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbp
add    %rbx,%rbp
test   $0x20,%r15b
je     11a1 <AddBitmapInfoString+0x81>
movups 0xea1(%rip),%xmm0
movups %xmm0,0x10(%rbp)
movups 0xe86(%rip),%xmm0
movups %xmm0,0x0(%rbp)
movw   $0xa,0x20(%rbp)
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbp
test   $0x10,%r15b
je     11d5 <AddBitmapInfoString+0xb5>
movups 0xe9f(%rip),%xmm0
movups %xmm0,0x1b(%rbp)
movups 0xe89(%rip),%xmm0
movups %xmm0,0x10(%rbp)
movups 0xe6e(%rip),%xmm0
movups %xmm0,0x0(%rbp)
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbp
and    $0x7,%r14d
shl    $0x11,%r14d
lea    0xe79(%rip),%rsi
mov    %rbp,%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbx
add    %rbp,%rbx
shl    $0x4,%r15d
and    $0x70,%r15d
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Bitmap(%dx%d)\0D\0A\00"
@.str.1 = [34 x i8] c"Bitmap Special Priority enabled\0D\0A\00"
@.str.2 = [43 x i8] c"Bitmap Special Color Calculation enabled\0D\0A\00"
@.str.3 = [22 x i8] c"Bitmap Address = %X\0D\0A\00"
@.str.4 = [30 x i8] c"Bitmap Palette Address = %X\0D\0A\00"
define i8* @AddBitmapInfoString(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%11 = load i32, i32* %6
switch i32 %11, label %16 [
i32 0, label %12
i32 1, label %13
i32 2, label %14
i32 3, label %15
]
12: ; preds = %4
store i32 512, i32* %9
store i32 256, i32* %10
br label %16
13: ; preds = %4
store i32 512, i32* %9
store i32 512, i32* %10
br label %16
14: ; preds = %4
store i32 1024, i32* %9
store i32 256, i32* %10
br label %16
15: ; preds = %4
store i32 1024, i32* %9
store i32 512, i32* %10
br label %16
16: ; preds = %4, %15, %14, %13, %12
%17 = load i8*, i8** %5
%18 = load i32, i32* %9
%19 = load i32, i32* %10
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19)
%21 = load i8*, i8** %5
%22 = call i32 @strlen(i8* %21)
%23 = load i8*, i8** %5
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8* %25, i8** %5
%26 = load i32, i32* %7
%27 = and i32 %26, 32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %16
%30 = load i8*, i8** %5
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %30, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%32 = load i8*, i8** %5
%33 = call i32 @strlen(i8* %32)
%34 = load i8*, i8** %5
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8* %36, i8** %5
br label %37
37: ; preds = %29, %16
%38 = load i32, i32* %7
%39 = and i32 %38, 16
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %49
41: ; preds = %37
%42 = load i8*, i8** %5
%43 = call i32 (i8*, i8*, ...) @sprintf(i8* %42, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%44 = load i8*, i8** %5
%45 = call i32 @strlen(i8* %44)
%46 = load i8*, i8** %5
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8* %48, i8** %5
br label %49
49: ; preds = %41, %37
%50 = load i8*, i8** %5
%51 = load i32, i32* %8
%52 = and i32 %51, 7
%53 = mul nsw i32 %52, 131072
%54 = call i32 (i8*, i8*, ...) @sprintf(i8* %50, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %53)
%55 = load i8*, i8** %5
%56 = call i32 @strlen(i8* %55)
%57 = load i8*, i8** %5
%58 = sext i32 %56 to i64
%59 = getelementptr inbounds i8, i8* %57, i64 %58
store i8* %59, i8** %5
%60 = load i8*, i8** %5
%61 = load i32, i32* %7
%62 = and i32 %61, 7
%63 = shl i32 %62, 4
%64 = call i32 (i8*, i8*, ...) @sprintf(i8* %60, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %63)
%65 = load i8*, i8** %5
%66 = call i32 @strlen(i8* %65)
%67 = load i8*, i8** %5
%68 = sext i32 %66 to i64
%69 = getelementptr inbounds i8, i8* %67, i64 %68
store i8* %69, i8** %5
%70 = load i8*, i8** %5
ret i8* %70
}

LLVM IR (-O2):
@.str = [16 x i8] c"Bitmap(%dx%d)\0D\0A\00"
@.str.1 = [34 x i8] c"Bitmap Special Priority enabled\0D\0A\00"
@.str.2 = [43 x i8] c"Bitmap Special Color Calculation enabled\0D\0A\00"
@.str.3 = [22 x i8] c"Bitmap Address = %X\0D\0A\00"
@.str.4 = [30 x i8] c"Bitmap Palette Address = %X\0D\0A\00"
@switch.table.AddBitmapInfoString = [4 x i32] [i32 512, i32 512, i32 1024, i32 1024]
@switch.table.AddBitmapInfoString.5 = [4 x i32] [i32 256, i32 512, i32 256, i32 512]
define i8* @AddBitmapInfoString(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp ult i32 %1, 4
br i1 %5, label %6, label %13
6: ; preds = %4
%7 = sext i32 %1 to i64
%8 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.AddBitmapInfoString, i64 0, i64 %7
%9 = load i32, i32* %8
%10 = sext i32 %1 to i64
%11 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.AddBitmapInfoString.5, i64 0, i64 %10
%12 = load i32, i32* %11
br label %13
13: ; preds = %6, %4
%14 = phi i32 [ 0, %4 ], [ %9, %6 ]
%15 = phi i32 [ 0, %4 ], [ %12, %6 ]
%16 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15)
%17 = tail call i32 @strlen(i8* %0)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = and i32 %2, 32
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %13
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(34) %19, i8* align 1 dereferenceable(34) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i64 34, i1 false)
%23 = tail call i32 @strlen(i8* %19)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %19, i64 %24
br label %26
26: ; preds = %22, %13
%27 = phi i8* [ %25, %22 ], [ %19, %13 ]
%28 = and i32 %2, 16
%29 = icmp eq i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %26
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(43) %27, i8* align 1 dereferenceable(43) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i64 43, i1 false)
%31 = tail call i32 @strlen(i8* %27)
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %27, i64 %32
br label %34
34: ; preds = %30, %26
%35 = phi i8* [ %33, %30 ], [ %27, %26 ]
%36 = shl i32 %3, 17
%37 = and i32 %36, 917504
%38 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %35, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = tail call i32 @strlen(i8* %35)
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %35, i64 %40
%42 = shl i32 %2, 4
%43 = and i32 %42, 112
%44 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %41, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %43)
%45 = tail call i32 @strlen(i8* %41)
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %41, i64 %46
ret i8* %47
}