#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*/ add_format_info(unsigned char *, int const, int const, int);
int evaluate(unsigned char *, int const);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int apply_bitmask(unsigned char *grid, const int size, const int ecc_level,
                  const int user_mask, const int debug_print) {
  int x, y;
  int r, k;
  int bit;
  int pattern, penalty[8];
  int best_pattern;
  int size_squared = size * size;
  unsigned char mask[size_squared];
  unsigned char local[size_squared];
  memset(mask, 0, size_squared);
  for (y = 0; y < size; y++) {
    r = y * size;
    for (x = 0; x < size; x++) {
      if (!(grid[r + x] & 0xf0)) {
        if (((y + x) & 1) == 0) {
          mask[r + x] |= 0x01;
        }
        if ((y & 1) == 0) {
          mask[r + x] |= 0x02;
        }
        if ((x % 3) == 0) {
          mask[r + x] |= 0x04;
        }
        if (((y + x) % 3) == 0) {
          mask[r + x] |= 0x08;
        }
        if ((((y / 2) + (x / 3)) & 1) == 0) {
          mask[r + x] |= 0x10;
        }
        if ((y * x) % 6 == 0) {
          mask[r + x] |= 0x20;
        }
        if (((((y * x) & 1) + ((y * x) % 3)) & 1) == 0) {
          mask[r + x] |= 0x40;
        }
        if (((((y + x) & 1) + ((y * x) % 3)) & 1) == 0) {
          mask[r + x] |= 0x80;
        }
      }
    }
  }
  if (user_mask) {
    best_pattern = user_mask - 1;
  } else {
    best_pattern = 0;
    for (pattern = 0; pattern < 8; pattern++) {
      bit = 1 << pattern;
      for (k = 0; k < size_squared; k++) {
        if (mask[k] & bit) {
          local[k] = grid[k] ^ 0x01;
        } else {
          local[k] = grid[k] & 0x0f;
        }
      }
      add_format_info(local, size, ecc_level, pattern);
      penalty[pattern] = evaluate(local, size);
      if (penalty[pattern] < penalty[best_pattern]) {
        best_pattern = pattern;
      }
    }
  }
  if (debug_print) {
    printf("Mask: %d (%s)", best_pattern,
           user_mask ? "specified" : "automatic");
    if (!user_mask) {
      for (pattern = 0; pattern < 8; pattern++)
        printf(" %d:%d", pattern, penalty[pattern]);
    }
    printf("\n");
  }
  if (!user_mask && best_pattern == 7) {
    memcpy(grid, local, size_squared);
  } else {
    bit = 1 << best_pattern;
    for (y = 0; y < size_squared; y++) {
      if (mask[y] & bit) {
        grid[y] ^= 0x01;
      }
    }
  }
  return best_pattern;
}


x86 assembly (clang, -O0):
<apply_bitmask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0xc(%rbp),%eax
imul   %eax,%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x80(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x68(%rbp)
mov    -0x58(%rbp),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x70(%rbp)
mov    -0x58(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    13f4 <apply_bitmask+0x2a4>
mov    -0x20(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    13e1 <apply_bitmask+0x291>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf0,%eax
cmp    $0x0,%eax
jne    13ce <apply_bitmask+0x27e>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    123c <apply_bitmask+0xec>
mov    -0x80(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
or     $0x1,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1262 <apply_bitmask+0x112>
mov    -0x80(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
or     $0x2,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    128d <apply_bitmask+0x13d>
mov    -0x80(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
or     $0x4,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12bb <apply_bitmask+0x16b>
mov    -0x80(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
or     $0x8,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x84(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x84(%rbp),%eax
add    %ecx,%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1304 <apply_bitmask+0x1b4>
mov    -0x80(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
or     $0x10,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    $0x6,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1333 <apply_bitmask+0x1e3>
mov    -0x80(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
or     $0x20,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
imul   -0x1c(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0x88(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    -0x88(%rbp),%eax
add    %edx,%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    137d <apply_bitmask+0x22d>
mov    -0x80(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
or     $0x40,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0x8c(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    -0x8c(%rbp),%eax
add    %edx,%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    13c9 <apply_bitmask+0x279>
mov    -0x80(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
or     $0x80,%edx
mov    %dl,(%rax,%rcx,1)
jmp    13ce <apply_bitmask+0x27e>
jmp    13d3 <apply_bitmask+0x283>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e8 <apply_bitmask+0x98>
jmp    13e6 <apply_bitmask+0x296>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11cb <apply_bitmask+0x7b>
cmpl   $0x0,-0x14(%rbp)
je     140c <apply_bitmask+0x2bc>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1508 <apply_bitmask+0x3b8>
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x8,-0x30(%rbp)
jge    1503 <apply_bitmask+0x3b3>
mov    -0x30(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    14ac <apply_bitmask+0x35c>
mov    -0x80(%rbp),%rax
movslq -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    -0x2c(%rbp),%eax
cmp    $0x0,%eax
je     147d <apply_bitmask+0x32d>
mov    -0x78(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x28(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
xor    $0x1,%ecx
mov    %cl,%dl
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1499 <apply_bitmask+0x349>
mov    -0x78(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x28(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
and    $0xf,%ecx
mov    %cl,%dl
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    149e <apply_bitmask+0x34e>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1438 <apply_bitmask+0x2e8>
mov    -0x78(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x30(%rbp),%ecx
call   1070 <add_format_info@plt>
mov    -0x78(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <evaluate@plt>
mov    %eax,%ecx
movslq -0x30(%rbp),%rax
mov    %ecx,-0x50(%rbp,%rax,4)
movslq -0x30(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%eax
movslq -0x54(%rbp),%rcx
cmp    -0x50(%rbp,%rcx,4),%eax
jge    14f0 <apply_bitmask+0x3a0>
mov    -0x30(%rbp),%eax
mov    %eax,-0x54(%rbp)
jmp    14f5 <apply_bitmask+0x3a5>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    141a <apply_bitmask+0x2ca>
jmp    1508 <apply_bitmask+0x3b8>
cmpl   $0x0,-0x18(%rbp)
je     1590 <apply_bitmask+0x440>
mov    -0x54(%rbp),%esi
mov    -0x14(%rbp),%ecx
lea    0xaf9(%rip),%rdx
lea    0xae8(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xacc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1582 <apply_bitmask+0x432>
movl   $0x0,-0x30(%rbp)
cmpl   $0x8,-0x30(%rbp)
jge    157d <apply_bitmask+0x42d>
mov    -0x30(%rbp),%esi
movslq -0x30(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%edx
lea    0xaba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    154c <apply_bitmask+0x3fc>
jmp    1582 <apply_bitmask+0x432>
lea    0xaa0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    15b9 <apply_bitmask+0x469>
cmpl   $0x7,-0x54(%rbp)
jne    15b9 <apply_bitmask+0x469>
mov    -0x78(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    -0x58(%rbp),%edx
call   1050 <memcpy@plt>
jmp    161b <apply_bitmask+0x4cb>
mov    -0x54(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    1616 <apply_bitmask+0x4c6>
mov    -0x80(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    -0x2c(%rbp),%eax
cmp    $0x0,%eax
je     1603 <apply_bitmask+0x4b3>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
xor    $0x1,%edx
mov    %dl,(%rax,%rcx,1)
jmp    1608 <apply_bitmask+0x4b8>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    15cd <apply_bitmask+0x47d>
jmp    161b <apply_bitmask+0x4cb>
mov    -0x54(%rbp),%eax
mov    -0x60(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apply_bitmask>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %r8d,-0x2c(%rbp)
mov    %rcx,-0x60(%rbp)
mov    %edx,-0x7c(%rbp)
mov    %esi,%ebx
mov    %rdi,-0x40(%rbp)
mov    %rsp,-0x38(%rbp)
mov    %esi,%edx
imul   %edx,%edx
mov    %rsp,%rdi
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdi
mov    %rdi,%rsp
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rdi,-0x48(%rbp)
xor    %esi,%esi
mov    %rdx,-0x88(%rbp)
call   1050 <memset@plt>
xor    %r11d,%r11d
mov    %ebx,-0x30(%rbp)
test   %ebx,%ebx
jle    1322 <apply_bitmask+0x1c2>
mov    -0x30(%rbp),%edx
mov    $0x1,%esi
mov    $0xaaaaaaab,%r8d
mov    -0x48(%rbp),%r9
mov    -0x40(%rbp),%rdi
xor    %eax,%eax
xor    %r14d,%r14d
mov    %rdx,-0x68(%rbp)
jmp    120d <apply_bitmask+0xad>
nopl   (%rax)
add    $0x1,%r14
add    $0x2,%eax
add    $0x1,%esi
add    $0xffffffff,%r11d
add    %rdx,%rdi
add    %rdx,%r9
cmp    %rdx,%r14
je     1322 <apply_bitmask+0x1c2>
mov    %r14d,%ecx
shr    %ecx
mov    %ecx,-0x70(%rbp)
xor    %ebx,%ebx
mov    %r14d,%ecx
mov    %r14d,%r15d
xor    %r13d,%r13d
xor    %r12d,%r12d
xor    %r10d,%r10d
mov    %esi,-0x58(%rbp)
mov    %rdi,-0x78(%rbp)
jmp    1248 <apply_bitmask+0xe8>
nop
add    $0x1,%r10
add    %eax,%r12d
add    %r14d,%r13d
add    %esi,%r15d
add    %r11d,%ebx
add    $0x1,%ecx
cmp    %r10,%rdx
je     11f0 <apply_bitmask+0x90>
cmpb   $0xf,(%rdi,%r10,1)
ja     1230 <apply_bitmask+0xd0>
mov    %ecx,%edi
imul   %r8,%rdi
mov    %r10d,%edx
imul   %r8,%rdx
shr    $0x21,%rdx
lea    (%r14,%r10,1),%esi
test   $0x1,%sil
jne    126f <apply_bitmask+0x10f>
orb    $0x1,(%r9,%r10,1)
shr    $0x21,%rdi
lea    (%rdx,%rdx,2),%edx
neg    %edx
test   $0x1,%r14b
jne    1283 <apply_bitmask+0x123>
orb    $0x2,(%r9,%r10,1)
mov    %r9,%rsi
lea    (%rdi,%rdi,2),%edi
neg    %edi
mov    %r10d,%r9d
imul   %r8,%r9
add    %r10d,%edx
mov    $0xaaaaaaab,%edx
jne    12a1 <apply_bitmask+0x141>
orb    $0x4,(%rsi,%r10,1)
mov    %r13d,%r8d
imul   %rdx,%r8
shr    $0x21,%r9
lea    (%r14,%r10,1),%edx
add    %edx,%edi
jne    12b9 <apply_bitmask+0x159>
orb    $0x8,(%rsi,%r10,1)
mov    %r8,%rdx
shr    $0x21,%rdx
shr    $0x22,%r8
add    -0x70(%rbp),%r9d
test   $0x1,%r9b
mov    %rsi,%r9
jne    12d6 <apply_bitmask+0x176>
orb    $0x10,(%r9,%r10,1)
lea    (%rdx,%rdx,2),%edi
mov    %r12d,%edx
sub    %edi,%edx
lea    (%r8,%r8,2),%esi
lea    (%rbx,%rsi,2),%esi
test   %esi,%esi
jne    12ee <apply_bitmask+0x18e>
orb    $0x20,(%r9,%r10,1)
mov    %r15d,%esi
sub    %edi,%esi
test   $0x1,%dl
mov    $0xaaaaaaab,%r8d
jne    1303 <apply_bitmask+0x1a3>
orb    $0x40,(%r9,%r10,1)
test   $0x1,%sil
mov    -0x68(%rbp),%rdx
mov    -0x58(%rbp),%esi
mov    -0x78(%rbp),%rdi
jne    1230 <apply_bitmask+0xd0>
orb    $0x80,(%r9,%r10,1)
jmp    1230 <apply_bitmask+0xd0>
mov    -0x60(%rbp),%rbx
test   %ebx,%ebx
je     1364 <apply_bitmask+0x204>
lea    -0x1(%rbx),%r15d
cmpl   $0x0,-0x2c(%rbp)
mov    -0x88(%rbp),%r13
je     1813 <apply_bitmask+0x6b3>
lea    0xcfa(%rip),%rdi
lea    0xd01(%rip),%rdx
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x38(%rbp),%r14
mov    -0x40(%rbp),%r12
jmp    17e4 <apply_bitmask+0x684>
mov    -0x88(%rbp),%r13
mov    %r13d,%eax
and    $0x7ffffff0,%eax
mov    %rax,-0x58(%rbp)
add    $0xfffffffffffffff0,%rax
mov    %rax,-0x70(%rbp)
mov    %rax,%rcx
shr    $0x4,%rcx
add    $0x1,%rcx
mov    %rcx,%rax
mov    %rcx,-0x68(%rbp)
and    $0xfffffffffffffffe,%rcx
mov    %rcx,-0xb8(%rbp)
mov    %r13d,%eax
and    $0x7ffffff8,%eax
mov    %rax,-0x78(%rbp)
xor    %r14d,%r14d
pxor   %xmm6,%xmm6
movdqa 0xc69(%rip),%xmm7
movdqa 0xc70(%rip),%xmm8
movdqa 0xc48(%rip),%xmm0
movdqa 0xc2f(%rip),%xmm10
xor    %r15d,%r15d
mov    -0x40(%rbp),%r12
mov    -0x50(%rbp),%rsi
jmp    144d <apply_bitmask+0x2ed>
xchg   %ax,%ax
mov    %rsi,%rdi
mov    -0x30(%rbp),%ebx
mov    %ebx,%esi
mov    -0x7c(%rbp),%edx
mov    %r14d,%ecx
call   1080 <add_format_info@plt>
mov    -0x50(%rbp),%rdi
mov    %ebx,%esi
call   1070 <evaluate@plt>
movdqa 0xbf9(%rip),%xmm10
movdqa 0xc01(%rip),%xmm0
movdqa 0xc18(%rip),%xmm8
movdqa 0xc00(%rip),%xmm7
pxor   %xmm6,%xmm6
mov    -0x50(%rbp),%rsi
mov    %eax,-0xb0(%rbp,%r14,4)
ff
movslq %r15d,%r15
cmp    -0xb0(%rbp,%r15,4),%eax
ff
cmovl  %r14d,%r15d
add    $0x1,%r14
cmp    $0x8,%r14
je     170e <apply_bitmask+0x5ae>
mov    $0x1,%r8d
mov    %r14d,%ecx
shl    %cl,%r8d
test   %r13,%r13
mov    -0x48(%rbp),%rdi
je     13e0 <apply_bitmask+0x280>
cmp    $0x8,%r13d
jae    1480 <apply_bitmask+0x320>
xor    %edx,%edx
jmp    16d0 <apply_bitmask+0x570>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movd   %r8d,%xmm9
cmp    $0x10,%r13d
jae    1492 <apply_bitmask+0x332>
xor    %ecx,%ecx
jmp    164d <apply_bitmask+0x4ed>
pshufd $0x0,%xmm9,%xmm1
cmpq   $0x0,-0x70(%rbp)
je     16fd <apply_bitmask+0x59d>
mov    -0xb8(%rbp),%rdx
xor    %ecx,%ecx
nopl   0x0(%rax)
movdqa (%rdi,%rcx,1),%xmm2
movdqa %xmm2,%xmm3
punpckhbw %xmm6,%xmm3
movdqa %xmm3,%xmm4
punpckhwd %xmm6,%xmm4
punpcklwd %xmm6,%xmm3
punpcklbw %xmm6,%xmm2
movdqa %xmm2,%xmm5
punpckhwd %xmm6,%xmm5
punpcklwd %xmm6,%xmm2
pand   %xmm1,%xmm2
pand   %xmm1,%xmm5
pand   %xmm1,%xmm3
pand   %xmm1,%xmm4
pcmpeqd %xmm6,%xmm4
pcmpeqd %xmm6,%xmm3
packssdw %xmm4,%xmm3
pcmpeqd %xmm6,%xmm5
pcmpeqd %xmm6,%xmm2
packssdw %xmm5,%xmm2
packsswb %xmm3,%xmm2
movdqu (%r12,%rcx,1),%xmm3
movdqa %xmm3,%xmm4
pxor   %xmm0,%xmm4
pand   %xmm10,%xmm3
pand   %xmm2,%xmm3
pandn  %xmm4,%xmm2
por    %xmm2,%xmm3
movdqa %xmm3,(%rsi,%rcx,1)
movdqa 0x10(%rdi,%rcx,1),%xmm2
movdqa %xmm2,%xmm3
punpckhbw %xmm6,%xmm3
movdqa %xmm3,%xmm4
punpckhwd %xmm6,%xmm4
punpcklwd %xmm6,%xmm3
punpcklbw %xmm6,%xmm2
movdqa %xmm2,%xmm5
punpckhwd %xmm6,%xmm5
punpcklwd %xmm6,%xmm2
pand   %xmm1,%xmm2
pand   %xmm1,%xmm5
pand   %xmm1,%xmm3
pand   %xmm1,%xmm4
pcmpeqd %xmm6,%xmm4
pcmpeqd %xmm6,%xmm3
packssdw %xmm4,%xmm3
pcmpeqd %xmm6,%xmm5
pcmpeqd %xmm6,%xmm2
packssdw %xmm5,%xmm2
packsswb %xmm3,%xmm2
movdqu 0x10(%r12,%rcx,1),%xmm3
movdqa %xmm3,%xmm4
pxor   %xmm0,%xmm4
pand   %xmm10,%xmm3
pand   %xmm2,%xmm3
pandn  %xmm4,%xmm2
por    %xmm2,%xmm3
movdqa %xmm3,0x10(%rsi,%rcx,1)
add    $0x20,%rcx
add    $0xfffffffffffffffe,%rdx
jne    14b0 <apply_bitmask+0x350>
testb  $0x1,-0x68(%rbp)
je     1632 <apply_bitmask+0x4d2>
movdqa (%rdi,%rcx,1),%xmm2
movdqa %xmm2,%xmm3
punpckhbw %xmm6,%xmm3
movdqa %xmm3,%xmm4
punpckhwd %xmm6,%xmm4
punpcklwd %xmm6,%xmm3
punpcklbw %xmm6,%xmm2
movdqa %xmm2,%xmm5
punpckhwd %xmm6,%xmm5
punpcklwd %xmm6,%xmm2
pand   %xmm1,%xmm2
pand   %xmm1,%xmm5
pand   %xmm1,%xmm3
pand   %xmm1,%xmm4
pcmpeqd %xmm6,%xmm4
pcmpeqd %xmm6,%xmm3
packssdw %xmm4,%xmm3
pcmpeqd %xmm6,%xmm5
pcmpeqd %xmm6,%xmm2
packssdw %xmm5,%xmm2
packsswb %xmm3,%xmm2
movdqu (%r12,%rcx,1),%xmm1
movdqa %xmm1,%xmm3
pand   %xmm2,%xmm3
pxor   %xmm0,%xmm1
pandn  %xmm1,%xmm2
pand   %xmm10,%xmm3
por    %xmm2,%xmm3
movdqa %xmm3,(%rsi,%rcx,1)
cmp    %r13,-0x58(%rbp)
je     13e0 <apply_bitmask+0x280>
mov    -0x58(%rbp),%rdx
mov    %rdx,%rcx
test   $0x8,%r13b
je     16d0 <apply_bitmask+0x570>
pshufd $0x0,%xmm9,%xmm0
mov    -0x78(%rbp),%rax
nopw   0x0(%rax,%rax,1)
movq   (%rdi,%rcx,1),%xmm1
punpcklbw %xmm6,%xmm1
movdqa %xmm1,%xmm2
punpckhwd %xmm6,%xmm2
punpcklwd %xmm6,%xmm1
pand   %xmm0,%xmm1
pand   %xmm0,%xmm2
pcmpeqd %xmm6,%xmm2
pcmpeqd %xmm6,%xmm1
packssdw %xmm2,%xmm1
packsswb %xmm1,%xmm1
movq   (%r12,%rcx,1),%xmm2
movdqa %xmm2,%xmm3
pand   %xmm1,%xmm3
pand   %xmm8,%xmm3
pxor   %xmm7,%xmm2
pandn  %xmm2,%xmm1
por    %xmm3,%xmm1
movq   %xmm1,(%rsi,%rcx,1)
add    $0x8,%rcx
cmp    %rcx,%rax
jne    1660 <apply_bitmask+0x500>
mov    %rax,%rdx
cmp    %r13,%rax
je     13e0 <apply_bitmask+0x280>
cs nopw 0x0(%rax,%rax,1)
movzbl (%rdi,%rdx,1),%ecx
movzbl (%r12,%rdx,1),%ebx
mov    %ebx,%eax
and    $0xf,%al
xor    $0x1,%bl
test   %ecx,%r8d
movzbl %al,%eax
movzbl %bl,%ecx
cmove  %eax,%ecx
mov    %cl,(%rsi,%rdx,1)
add    $0x1,%rdx
cmp    %rdx,%r13
jne    16d0 <apply_bitmask+0x570>
jmp    13e0 <apply_bitmask+0x280>
xor    %ecx,%ecx
testb  $0x1,-0x68(%rbp)
jne    15b9 <apply_bitmask+0x459>
jmp    1632 <apply_bitmask+0x4d2>
cmpl   $0x0,-0x2c(%rbp)
je     1897 <apply_bitmask+0x737>
lea    0x921(%rip),%rdi
lea    0x932(%rip),%rdx
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0xb0(%rbp),%edx
lea    0x925(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0xac(%rbp),%edx
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0xa8(%rbp),%edx
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0xa4(%rbp),%edx
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0xa0(%rbp),%edx
mov    %r14,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x9c(%rbp),%edx
mov    %r14,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x98(%rbp),%edx
mov    %r14,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x94(%rbp),%edx
mov    %r14,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x38(%rbp),%r14
mov    -0x60(%rbp),%rbx
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x50(%rbp),%rsi
test   %ebx,%ebx
mov    -0x48(%rbp),%rdi
jne    181f <apply_bitmask+0x6bf>
cmp    $0x7,%r15d
jne    181f <apply_bitmask+0x6bf>
mov    %r12,%rdi
mov    %r13d,%edx
call   1060 <memcpy@plt>
mov    $0x7,%r15d
jmp    1849 <apply_bitmask+0x6e9>
mov    -0x38(%rbp),%r14
mov    -0x40(%rbp),%r12
mov    -0x48(%rbp),%rdi
mov    $0x1,%eax
mov    %r15d,%ecx
shl    %cl,%eax
test   %r13,%r13
je     1849 <apply_bitmask+0x6e9>
cmp    $0x1,%r13d
jne    185e <apply_bitmask+0x6fe>
xor    %ecx,%ecx
test   $0x1,%r13b
je     1849 <apply_bitmask+0x6e9>
movzbl (%rdi,%rcx,1),%edx
test   %edx,%eax
je     1849 <apply_bitmask+0x6e9>
xorb   $0x1,(%r12,%rcx,1)
mov    %r14,%rsp
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13d,%edx
and    $0x7ffffffe,%edx
xor    %ecx,%ecx
jmp    1879 <apply_bitmask+0x719>
nopl   0x0(%rax,%rax,1)
add    $0x2,%rcx
cmp    %rcx,%rdx
je     1836 <apply_bitmask+0x6d6>
movzbl (%rdi,%rcx,1),%esi
test   %esi,%eax
je     1886 <apply_bitmask+0x726>
xorb   $0x1,(%r12,%rcx,1)
movzbl 0x1(%rdi,%rcx,1),%esi
test   %esi,%eax
je     1870 <apply_bitmask+0x710>
xorb   $0x1,0x1(%r12,%rcx,1)
jmp    1870 <apply_bitmask+0x710>
mov    -0x38(%rbp),%r14
mov    -0x60(%rbp),%rbx
jmp    17f2 <apply_bitmask+0x692>

LLVM IR (-O0):
@.str = [14 x i8] c"Mask: %d (%s)\00"
@.str.1 = [10 x i8] c"specified\00"
@.str.2 = [10 x i8] c"automatic\00"
@.str.3 = [7 x i8] c" %d:%d\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @apply_bitmask(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca [8 x i32]
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8*
%21 = alloca i64
%22 = alloca i64
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%23 = load i32, i32* %7
%24 = load i32, i32* %7
%25 = mul nsw i32 %23, %24
store i32 %25, i32* %19
%26 = load i32, i32* %19
%27 = zext i32 %26 to i64
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %20
%29 = alloca i8, i64 %27
store i64 %27, i64* %21
%30 = load i32, i32* %19
%31 = zext i32 %30 to i64
%32 = alloca i8, i64 %31
store i64 %31, i64* %22
%33 = load i32, i32* %19
%34 = call i32 @memset(i8* %29, i32 0, i32 %33)
store i32 0, i32* %12
br label %35
35: ; preds = %202, %5
%36 = load i32, i32* %12
%37 = load i32, i32* %7
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %205
39: ; preds = %35
%40 = load i32, i32* %12
%41 = load i32, i32* %7
%42 = mul nsw i32 %40, %41
store i32 %42, i32* %13
store i32 0, i32* %11
br label %43
43: ; preds = %198, %39
%44 = load i32, i32* %11
%45 = load i32, i32* %7
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %201
47: ; preds = %43
%48 = load i8*, i8** %6
%49 = load i32, i32* %13
%50 = load i32, i32* %11
%51 = add nsw i32 %49, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %48, i64 %52
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = and i32 %55, 240
%57 = icmp ne i32 %56, 0
br i1 %57, label %197, label %58
58: ; preds = %47
%59 = load i32, i32* %12
%60 = load i32, i32* %11
%61 = add nsw i32 %59, %60
%62 = and i32 %61, 1
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %74
64: ; preds = %58
%65 = load i32, i32* %13
%66 = load i32, i32* %11
%67 = add nsw i32 %65, %66
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %29, i64 %68
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = or i32 %71, 1
%73 = trunc i32 %72 to i8
store i8 %73, i8* %69
br label %74
74: ; preds = %64, %58
%75 = load i32, i32* %12
%76 = and i32 %75, 1
%77 = icmp eq i32 %76, 0
br i1 %77, label %78, label %88
78: ; preds = %74
%79 = load i32, i32* %13
%80 = load i32, i32* %11
%81 = add nsw i32 %79, %80
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %29, i64 %82
%84 = load i8, i8* %83
%85 = zext i8 %84 to i32
%86 = or i32 %85, 2
%87 = trunc i32 %86 to i8
store i8 %87, i8* %83
br label %88
88: ; preds = %78, %74
%89 = load i32, i32* %11
%90 = srem i32 %89, 3
%91 = icmp eq i32 %90, 0
br i1 %91, label %92, label %102
92: ; preds = %88
%93 = load i32, i32* %13
%94 = load i32, i32* %11
%95 = add nsw i32 %93, %94
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %29, i64 %96
%98 = load i8, i8* %97
%99 = zext i8 %98 to i32
%100 = or i32 %99, 4
%101 = trunc i32 %100 to i8
store i8 %101, i8* %97
br label %102
102: ; preds = %92, %88
%103 = load i32, i32* %12
%104 = load i32, i32* %11
%105 = add nsw i32 %103, %104
%106 = srem i32 %105, 3
%107 = icmp eq i32 %106, 0
br i1 %107, label %108, label %118
108: ; preds = %102
%109 = load i32, i32* %13
%110 = load i32, i32* %11
%111 = add nsw i32 %109, %110
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i8, i8* %29, i64 %112
%114 = load i8, i8* %113
%115 = zext i8 %114 to i32
%116 = or i32 %115, 8
%117 = trunc i32 %116 to i8
store i8 %117, i8* %113
br label %118
118: ; preds = %108, %102
%119 = load i32, i32* %12
%120 = sdiv i32 %119, 2
%121 = load i32, i32* %11
%122 = sdiv i32 %121, 3
%123 = add nsw i32 %120, %122
%124 = and i32 %123, 1
%125 = icmp eq i32 %124, 0
br i1 %125, label %126, label %136
126: ; preds = %118
%127 = load i32, i32* %13
%128 = load i32, i32* %11
%129 = add nsw i32 %127, %128
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds i8, i8* %29, i64 %130
%132 = load i8, i8* %131
%133 = zext i8 %132 to i32
%134 = or i32 %133, 16
%135 = trunc i32 %134 to i8
store i8 %135, i8* %131
br label %136
136: ; preds = %126, %118
%137 = load i32, i32* %12
%138 = load i32, i32* %11
%139 = mul nsw i32 %137, %138
%140 = srem i32 %139, 6
%141 = icmp eq i32 %140, 0
br i1 %141, label %142, label %152
142: ; preds = %136
%143 = load i32, i32* %13
%144 = load i32, i32* %11
%145 = add nsw i32 %143, %144
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds i8, i8* %29, i64 %146
%148 = load i8, i8* %147
%149 = zext i8 %148 to i32
%150 = or i32 %149, 32
%151 = trunc i32 %150 to i8
store i8 %151, i8* %147
br label %152
152: ; preds = %142, %136
%153 = load i32, i32* %12
%154 = load i32, i32* %11
%155 = mul nsw i32 %153, %154
%156 = and i32 %155, 1
%157 = load i32, i32* %12
%158 = load i32, i32* %11
%159 = mul nsw i32 %157, %158
%160 = srem i32 %159, 3
%161 = add nsw i32 %156, %160
%162 = and i32 %161, 1
%163 = icmp eq i32 %162, 0
br i1 %163, label %164, label %174
164: ; preds = %152
%165 = load i32, i32* %13
%166 = load i32, i32* %11
%167 = add nsw i32 %165, %166
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds i8, i8* %29, i64 %168
%170 = load i8, i8* %169
%171 = zext i8 %170 to i32
%172 = or i32 %171, 64
%173 = trunc i32 %172 to i8
store i8 %173, i8* %169
br label %174
174: ; preds = %164, %152
%175 = load i32, i32* %12
%176 = load i32, i32* %11
%177 = add nsw i32 %175, %176
%178 = and i32 %177, 1
%179 = load i32, i32* %12
%180 = load i32, i32* %11
%181 = mul nsw i32 %179, %180
%182 = srem i32 %181, 3
%183 = add nsw i32 %178, %182
%184 = and i32 %183, 1
%185 = icmp eq i32 %184, 0
br i1 %185, label %186, label %196
186: ; preds = %174
%187 = load i32, i32* %13
%188 = load i32, i32* %11
%189 = add nsw i32 %187, %188
%190 = sext i32 %189 to i64
%191 = getelementptr inbounds i8, i8* %29, i64 %190
%192 = load i8, i8* %191
%193 = zext i8 %192 to i32
%194 = or i32 %193, 128
%195 = trunc i32 %194 to i8
store i8 %195, i8* %191
br label %196
196: ; preds = %186, %174
br label %197
197: ; preds = %196, %47
br label %198
198: ; preds = %197
%199 = load i32, i32* %11
%200 = add nsw i32 %199, 1
store i32 %200, i32* %11
br label %43
201: ; preds = %43
br label %202
202: ; preds = %201
%203 = load i32, i32* %12
%204 = add nsw i32 %203, 1
store i32 %204, i32* %12
br label %35
205: ; preds = %35
%206 = load i32, i32* %9
%207 = icmp ne i32 %206, 0
br i1 %207, label %208, label %211
208: ; preds = %205
%209 = load i32, i32* %9
%210 = sub nsw i32 %209, 1
store i32 %210, i32* %18
br label %285
211: ; preds = %205
store i32 0, i32* %18
store i32 0, i32* %16
br label %212
212: ; preds = %281, %211
%213 = load i32, i32* %16
%214 = icmp slt i32 %213, 8
br i1 %214, label %215, label %284
215: ; preds = %212
%216 = load i32, i32* %16
%217 = shl i32 1, %216
store i32 %217, i32* %15
store i32 0, i32* %14
br label %218
218: ; preds = %256, %215
%219 = load i32, i32* %14
%220 = load i32, i32* %19
%221 = icmp slt i32 %219, %220
br i1 %221, label %222, label %259
222: ; preds = %218
%223 = load i32, i32* %14
%224 = sext i32 %223 to i64
%225 = getelementptr inbounds i8, i8* %29, i64 %224
%226 = load i8, i8* %225
%227 = zext i8 %226 to i32
%228 = load i32, i32* %15
%229 = and i32 %227, %228
%230 = icmp ne i32 %229, 0
br i1 %230, label %231, label %243
231: ; preds = %222
%232 = load i8*, i8** %6
%233 = load i32, i32* %14
%234 = sext i32 %233 to i64
%235 = getelementptr inbounds i8, i8* %232, i64 %234
%236 = load i8, i8* %235
%237 = zext i8 %236 to i32
%238 = xor i32 %237, 1
%239 = trunc i32 %238 to i8
%240 = load i32, i32* %14
%241 = sext i32 %240 to i64
%242 = getelementptr inbounds i8, i8* %32, i64 %241
store i8 %239, i8* %242
br label %255
243: ; preds = %222
%244 = load i8*, i8** %6
%245 = load i32, i32* %14
%246 = sext i32 %245 to i64
%247 = getelementptr inbounds i8, i8* %244, i64 %246
%248 = load i8, i8* %247
%249 = zext i8 %248 to i32
%250 = and i32 %249, 15
%251 = trunc i32 %250 to i8
%252 = load i32, i32* %14
%253 = sext i32 %252 to i64
%254 = getelementptr inbounds i8, i8* %32, i64 %253
store i8 %251, i8* %254
br label %255
255: ; preds = %243, %231
br label %256
256: ; preds = %255
%257 = load i32, i32* %14
%258 = add nsw i32 %257, 1
store i32 %258, i32* %14
br label %218
259: ; preds = %218
%260 = load i32, i32* %7
%261 = load i32, i32* %8
%262 = load i32, i32* %16
%263 = call i32 @add_format_info(i8* %32, i32 %260, i32 %261, i32 %262)
%264 = load i32, i32* %7
%265 = call i32 @evaluate(i8* %32, i32 %264)
%266 = load i32, i32* %16
%267 = sext i32 %266 to i64
%268 = getelementptr inbounds [8 x i32], [8 x i32]* %17, i64 0, i64 %267
store i32 %265, i32* %268
%269 = load i32, i32* %16
%270 = sext i32 %269 to i64
%271 = getelementptr inbounds [8 x i32], [8 x i32]* %17, i64 0, i64 %270
%272 = load i32, i32* %271
%273 = load i32, i32* %18
%274 = sext i32 %273 to i64
%275 = getelementptr inbounds [8 x i32], [8 x i32]* %17, i64 0, i64 %274
%276 = load i32, i32* %275
%277 = icmp slt i32 %272, %276
br i1 %277, label %278, label %280
278: ; preds = %259
%279 = load i32, i32* %16
store i32 %279, i32* %18
br label %280
280: ; preds = %278, %259
br label %281
281: ; preds = %280
%282 = load i32, i32* %16
%283 = add nsw i32 %282, 1
store i32 %283, i32* %16
br label %212
284: ; preds = %212
br label %285
285: ; preds = %284, %208
%286 = load i32, i32* %10
%287 = icmp ne i32 %286, 0
br i1 %287, label %288, label %314
288: ; preds = %285
%289 = load i32, i32* %18
%290 = load i32, i32* %9
%291 = icmp ne i32 %290, 0
%292 = zext i1 %291 to i64
%293 = select i1 %291, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
%294 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %289, i8* %293)
%295 = load i32, i32* %9
%296 = icmp ne i32 %295, 0
br i1 %296, label %312, label %297
297: ; preds = %288
store i32 0, i32* %16
br label %298
298: ; preds = %308, %297
%299 = load i32, i32* %16
%300 = icmp slt i32 %299, 8
br i1 %300, label %301, label %311
301: ; preds = %298
%302 = load i32, i32* %16
%303 = load i32, i32* %16
%304 = sext i32 %303 to i64
%305 = getelementptr inbounds [8 x i32], [8 x i32]* %17, i64 0, i64 %304
%306 = load i32, i32* %305
%307 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %302, i32 %306)
br label %308
308: ; preds = %301
%309 = load i32, i32* %16
%310 = add nsw i32 %309, 1
store i32 %310, i32* %16
br label %298
311: ; preds = %298
br label %312
312: ; preds = %311, %288
%313 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %314
314: ; preds = %312, %285
%315 = load i32, i32* %9
%316 = icmp ne i32 %315, 0
br i1 %316, label %324, label %317
317: ; preds = %314
%318 = load i32, i32* %18
%319 = icmp eq i32 %318, 7
br i1 %319, label %320, label %324
320: ; preds = %317
%321 = load i8*, i8** %6
%322 = load i32, i32* %19
%323 = call i32 @memcpy(i8* %321, i8* %32, i32 %322)
br label %354
324: ; preds = %317, %314
%325 = load i32, i32* %18
%326 = shl i32 1, %325
store i32 %326, i32* %15
store i32 0, i32* %12
br label %327
327: ; preds = %350, %324
%328 = load i32, i32* %12
%329 = load i32, i32* %19
%330 = icmp slt i32 %328, %329
br i1 %330, label %331, label %353
331: ; preds = %327
%332 = load i32, i32* %12
%333 = sext i32 %332 to i64
%334 = getelementptr inbounds i8, i8* %29, i64 %333
%335 = load i8, i8* %334
%336 = zext i8 %335 to i32
%337 = load i32, i32* %15
%338 = and i32 %336, %337
%339 = icmp ne i32 %338, 0
br i1 %339, label %340, label %349
340: ; preds = %331
%341 = load i8*, i8** %6
%342 = load i32, i32* %12
%343 = sext i32 %342 to i64
%344 = getelementptr inbounds i8, i8* %341, i64 %343
%345 = load i8, i8* %344
%346 = zext i8 %345 to i32
%347 = xor i32 %346, 1
%348 = trunc i32 %347 to i8
store i8 %348, i8* %344
br label %349
349: ; preds = %340, %331
br label %350
350: ; preds = %349
%351 = load i32, i32* %12
%352 = add nsw i32 %351, 1
store i32 %352, i32* %12
br label %327
353: ; preds = %327
br label %354
354: ; preds = %353, %320
%355 = load i32, i32* %18
%356 = load i8*, i8** %20
ret i32 %355
}

LLVM IR (-O2):
@.str = [14 x i8] c"Mask: %d (%s)\00"
@.str.1 = [10 x i8] c"specified\00"
@.str.2 = [10 x i8] c"automatic\00"
@.str.3 = [7 x i8] c" %d:%d\00"
define i32 @apply_bitmask(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [8 x i32]
%7 = bitcast [8 x i32]* %6 to i8*
%8 = mul nsw i32 %1, %1
%9 = zext i32 %8 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = alloca i8, i64 %9
%13 = call i32 @memset(i8* %11, i32 0, i32 %8)
%14 = icmp sgt i32 %1, 0
br i1 %14, label %15, label %101
15: ; preds = %5
%16 = zext i32 %1 to i64
%17 = zext i32 %1 to i64
br label %18
18: ; preds = %98, %15
%19 = phi i64 [ 0, %15 ], [ %99, %98 ]
%20 = mul nsw i64 %19, %16
%21 = trunc i64 %19 to i32
%22 = and i32 %21, 1
%23 = icmp eq i32 %22, 0
%24 = lshr i32 %21, 1
br label %25
25: ; preds = %18, %95
%26 = phi i64 [ 0, %18 ], [ %96, %95 ]
%27 = add nuw nsw i64 %26, %20
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = load i8, i8* %28
%30 = icmp ult i8 %29, 16
br i1 %30, label %31, label %95
31: ; preds = %25
%32 = add nuw nsw i64 %26, %19
%33 = trunc i64 %32 to i32
%34 = and i32 %33, 1
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = getelementptr inbounds i8, i8* %11, i64 %27
%38 = load i8, i8* %37
%39 = or i8 %38, 1
store i8 %39, i8* %37
br label %40
40: ; preds = %36, %31
br i1 %23, label %41, label %45
41: ; preds = %40
%42 = getelementptr inbounds i8, i8* %11, i64 %27
%43 = load i8, i8* %42
%44 = or i8 %43, 2
store i8 %44, i8* %42
br label %45
45: ; preds = %41, %40
%46 = trunc i64 %26 to i32
%47 = urem i32 %46, 3
%48 = udiv i32 %46, 3
%49 = icmp eq i32 %47, 0
br i1 %49, label %50, label %54
50: ; preds = %45
%51 = getelementptr inbounds i8, i8* %11, i64 %27
%52 = load i8, i8* %51
%53 = or i8 %52, 4
store i8 %53, i8* %51
br label %54
54: ; preds = %50, %45
%55 = urem i32 %33, 3
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %54
%58 = getelementptr inbounds i8, i8* %11, i64 %27
%59 = load i8, i8* %58
%60 = or i8 %59, 8
store i8 %60, i8* %58
br label %61
61: ; preds = %57, %54
%62 = add nuw nsw i32 %48, %24
%63 = and i32 %62, 1
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %61
%66 = getelementptr inbounds i8, i8* %11, i64 %27
%67 = load i8, i8* %66
%68 = or i8 %67, 16
store i8 %68, i8* %66
br label %69
69: ; preds = %65, %61
%70 = mul nuw nsw i64 %26, %19
%71 = trunc i64 %70 to i32
%72 = urem i32 %71, 6
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %69
%75 = getelementptr inbounds i8, i8* %11, i64 %27
%76 = load i8, i8* %75
%77 = or i8 %76, 32
store i8 %77, i8* %75
br label %78
78: ; preds = %74, %69
%79 = urem i32 %71, 3
%80 = add nuw i32 %79, %71
%81 = and i32 %80, 1
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %87
83: ; preds = %78
%84 = getelementptr inbounds i8, i8* %11, i64 %27
%85 = load i8, i8* %84
%86 = or i8 %85, 64
store i8 %86, i8* %84
br label %87
87: ; preds = %83, %78
%88 = add nuw i32 %79, %33
%89 = and i32 %88, 1
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %95
91: ; preds = %87
%92 = getelementptr inbounds i8, i8* %11, i64 %27
%93 = load i8, i8* %92
%94 = or i8 %93, -128
store i8 %94, i8* %92
br label %95
95: ; preds = %25, %91, %87
%96 = add nuw nsw i64 %26, 1
%97 = icmp eq i64 %96, %17
br i1 %97, label %98, label %25
98: ; preds = %95
%99 = add nuw nsw i64 %19, 1
%100 = icmp eq i64 %99, %17
br i1 %100, label %101, label %18
101: ; preds = %98, %5
%102 = icmp eq i32 %3, 0
br i1 %102, label %103, label %238
103: ; preds = %101
%104 = icmp eq i32 %8, 0
%105 = and i64 %9, 2147483632
%106 = add nsw i64 %105, -16
%107 = lshr exact i64 %106, 4
%108 = add nuw nsw i64 %107, 1
%109 = icmp ult i32 %8, 8
%110 = icmp ult i32 %8, 16
%111 = and i64 %9, 2147483632
%112 = and i64 %108, 1
%113 = icmp eq i64 %106, 0
%114 = and i64 %108, 2305843009213693950
%115 = icmp eq i64 %112, 0
%116 = icmp eq i64 %111, %9
%117 = and i64 %9, 8
%118 = icmp eq i64 %117, 0
%119 = and i64 %9, 2147483640
%120 = icmp eq i64 %119, %9
br label %121
121: ; preds = %103, %225
%122 = phi i64 [ 0, %103 ], [ %234, %225 ]
%123 = phi i32 [ 0, %103 ], [ %233, %225 ]
%124 = trunc i64 %122 to i32
%125 = shl nuw nsw i32 1, %124
br i1 %104, label %225, label %126
126: ; preds = %121
br i1 %109, label %208, label %127
127: ; preds = %126
br i1 %110, label %185, label %128
128: ; preds = %127
%129 = insertelement <16 x i32> poison, i32 %125, i64 0
%130 = shufflevector <16 x i32> %129, <16 x i32> poison, <16 x i32> zeroinitializer
br i1 %113, label %166, label %131
131: ; preds = %128, %131
%132 = phi i64 [ %163, %131 ], [ 0, %128 ]
%133 = phi i64 [ %164, %131 ], [ 0, %128 ]
%134 = getelementptr inbounds i8, i8* %11, i64 %132
%135 = bitcast i8* %134 to <16 x i8>*
%136 = load <16 x i8>, <16 x i8>* %135
%137 = zext <16 x i8> %136 to <16 x i32>
%138 = and <16 x i32> %130, %137
%139 = icmp eq <16 x i32> %138, zeroinitializer
%140 = getelementptr inbounds i8, i8* %0, i64 %132
%141 = bitcast i8* %140 to <16 x i8>*
%142 = load <16 x i8>, <16 x i8>* %141
%143 = and <16 x i8> %142, <i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15>
%144 = xor <16 x i8> %142, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
%145 = select <16 x i1> %139, <16 x i8> %143, <16 x i8> %144
%146 = getelementptr inbounds i8, i8* %12, i64 %132
%147 = bitcast i8* %146 to <16 x i8>*
store <16 x i8> %145, <16 x i8>* %147
%148 = or i64 %132, 16
%149 = getelementptr inbounds i8, i8* %11, i64 %148
%150 = bitcast i8* %149 to <16 x i8>*
%151 = load <16 x i8>, <16 x i8>* %150
%152 = zext <16 x i8> %151 to <16 x i32>
%153 = and <16 x i32> %130, %152
%154 = icmp eq <16 x i32> %153, zeroinitializer
%155 = getelementptr inbounds i8, i8* %0, i64 %148
%156 = bitcast i8* %155 to <16 x i8>*
%157 = load <16 x i8>, <16 x i8>* %156
%158 = and <16 x i8> %157, <i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15>
%159 = xor <16 x i8> %157, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
%160 = select <16 x i1> %154, <16 x i8> %158, <16 x i8> %159
%161 = getelementptr inbounds i8, i8* %12, i64 %148
%162 = bitcast i8* %161 to <16 x i8>*
store <16 x i8> %160, <16 x i8>* %162
%163 = add nuw i64 %132, 32
%164 = add i64 %133, 2
%165 = icmp eq i64 %164, %114
br i1 %165, label %166, label %131
166: ; preds = %131, %128
%167 = phi i64 [ 0, %128 ], [ %163, %131 ]
br i1 %115, label %183, label %168
168: ; preds = %166
%169 = getelementptr inbounds i8, i8* %11, i64 %167
%170 = bitcast i8* %169 to <16 x i8>*
%171 = load <16 x i8>, <16 x i8>* %170
%172 = zext <16 x i8> %171 to <16 x i32>
%173 = and <16 x i32> %130, %172
%174 = icmp eq <16 x i32> %173, zeroinitializer
%175 = getelementptr inbounds i8, i8* %0, i64 %167
%176 = bitcast i8* %175 to <16 x i8>*
%177 = load <16 x i8>, <16 x i8>* %176
%178 = and <16 x i8> %177, <i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15>
%179 = xor <16 x i8> %177, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
%180 = select <16 x i1> %174, <16 x i8> %178, <16 x i8> %179
%181 = getelementptr inbounds i8, i8* %12, i64 %167
%182 = bitcast i8* %181 to <16 x i8>*
store <16 x i8> %180, <16 x i8>* %182
br label %183
183: ; preds = %166, %168
br i1 %116, label %225, label %184
184: ; preds = %183
br i1 %118, label %208, label %185
185: ; preds = %127, %184
%186 = phi i64 [ %111, %184 ], [ 0, %127 ]
%187 = insertelement <8 x i32> poison, i32 %125, i64 0
%188 = shufflevector <8 x i32> %187, <8 x i32> poison, <8 x i32> zeroinitializer
br label %189
189: ; preds = %189, %185
%190 = phi i64 [ %186, %185 ], [ %205, %189 ]
%191 = getelementptr inbounds i8, i8* %11, i64 %190
%192 = bitcast i8* %191 to <8 x i8>*
%193 = load <8 x i8>, <8 x i8>* %192
%194 = zext <8 x i8> %193 to <8 x i32>
%195 = and <8 x i32> %188, %194
%196 = icmp eq <8 x i32> %195, zeroinitializer
%197 = getelementptr inbounds i8, i8* %0, i64 %190
%198 = bitcast i8* %197 to <8 x i8>*
%199 = load <8 x i8>, <8 x i8>* %198
%200 = and <8 x i8> %199, <i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15>
%201 = xor <8 x i8> %199, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
%202 = select <8 x i1> %196, <8 x i8> %200, <8 x i8> %201
%203 = getelementptr inbounds i8, i8* %12, i64 %190
%204 = bitcast i8* %203 to <8 x i8>*
store <8 x i8> %202, <8 x i8>* %204
%205 = add nuw i64 %190, 8
%206 = icmp eq i64 %205, %119
br i1 %206, label %207, label %189
207: ; preds = %189
br i1 %120, label %225, label %208
208: ; preds = %126, %184, %207
%209 = phi i64 [ 0, %126 ], [ %111, %184 ], [ %119, %207 ]
br label %210
210: ; preds = %208, %210
%211 = phi i64 [ %223, %210 ], [ %209, %208 ]
%212 = getelementptr inbounds i8, i8* %11, i64 %211
%213 = load i8, i8* %212
%214 = zext i8 %213 to i32
%215 = and i32 %125, %214
%216 = icmp eq i32 %215, 0
%217 = getelementptr inbounds i8, i8* %0, i64 %211
%218 = load i8, i8* %217
%219 = and i8 %218, 15
%220 = xor i8 %218, 1
%221 = select i1 %216, i8 %219, i8 %220
%222 = getelementptr inbounds i8, i8* %12, i64 %211
store i8 %221, i8* %222
%223 = add nuw nsw i64 %211, 1
%224 = icmp eq i64 %223, %9
br i1 %224, label %225, label %210
225: ; preds = %210, %183, %207, %121
%226 = call i32 @add_format_info(i8* %12, i32 %1, i32 %2, i32 %124)
%227 = call i32 @evaluate(i8* %12, i32 %1)
%228 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 %122
store i32 %227, i32* %228
%229 = sext i32 %123 to i64
%230 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 %229
%231 = load i32, i32* %230
%232 = icmp slt i32 %227, %231
%233 = select i1 %232, i32 %124, i32 %123
%234 = add nuw nsw i64 %122, 1
%235 = icmp eq i64 %234, 8
br i1 %235, label %236, label %121
236: ; preds = %225
%237 = icmp eq i32 %4, 0
br i1 %237, label %272, label %243
238: ; preds = %101
%239 = add nsw i32 %3, -1
%240 = icmp eq i32 %4, 0
br i1 %240, label %278, label %241
241: ; preds = %238
%242 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %239, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %269
243: ; preds = %236
%244 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %233, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%245 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 0
%246 = load i32, i32* %245
%247 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 %246)
%248 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 1
%249 = load i32, i32* %248
%250 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 %249)
%251 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 2
%252 = load i32, i32* %251
%253 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 2, i32 %252)
%254 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 3
%255 = load i32, i32* %254
%256 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 3, i32 %255)
%257 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 4
%258 = load i32, i32* %257
%259 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 4, i32 %258)
%260 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 5
%261 = load i32, i32* %260
%262 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 5, i32 %261)
%263 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 6
%264 = load i32, i32* %263
%265 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6, i32 %264)
%266 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 7
%267 = load i32, i32* %266
%268 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 7, i32 %267)
br label %269
269: ; preds = %243, %241
%270 = phi i32 [ %239, %241 ], [ %233, %243 ]
%271 = call i32 @putchar(i32 10)
br label %272
272: ; preds = %269, %236
%273 = phi i32 [ %270, %269 ], [ %233, %236 ]
%274 = icmp eq i32 %273, 7
%275 = select i1 %102, i1 %274, i1 false
br i1 %275, label %276, label %278
276: ; preds = %272
%277 = call i32 @memcpy(i8* %0, i8* %12, i32 %8)
br label %327
278: ; preds = %238, %272
%279 = phi i32 [ %273, %272 ], [ %239, %238 ]
%280 = shl nuw i32 1, %279
%281 = icmp eq i32 %8, 0
br i1 %281, label %327, label %282
282: ; preds = %278
%283 = and i64 %9, 1
%284 = icmp eq i32 %8, 1
br i1 %284, label %314, label %285
285: ; preds = %282
%286 = and i64 %9, 2147483646
br label %287
287: ; preds = %310, %285
%288 = phi i64 [ 0, %285 ], [ %311, %310 ]
%289 = phi i64 [ 0, %285 ], [ %312, %310 ]
%290 = getelementptr inbounds i8, i8* %11, i64 %288
%291 = load i8, i8* %290
%292 = zext i8 %291 to i32
%293 = and i32 %280, %292
%294 = icmp eq i32 %293, 0
br i1 %294, label %299, label %295
295: ; preds = %287
%296 = getelementptr inbounds i8, i8* %0, i64 %288
%297 = load i8, i8* %296
%298 = xor i8 %297, 1
store i8 %298, i8* %296
br label %299
299: ; preds = %287, %295
%300 = or i64 %288, 1
%301 = getelementptr inbounds i8, i8* %11, i64 %300
%302 = load i8, i8* %301
%303 = zext i8 %302 to i32
%304 = and i32 %280, %303
%305 = icmp eq i32 %304, 0
br i1 %305, label %310, label %306
306: ; preds = %299
%307 = getelementptr inbounds i8, i8* %0, i64 %300
%308 = load i8, i8* %307
%309 = xor i8 %308, 1
store i8 %309, i8* %307
br label %310
310: ; preds = %306, %299
%311 = add nuw nsw i64 %288, 2
%312 = add i64 %289, 2
%313 = icmp eq i64 %312, %286
br i1 %313, label %314, label %287
314: ; preds = %310, %282
%315 = phi i64 [ 0, %282 ], [ %311, %310 ]
%316 = icmp eq i64 %283, 0
br i1 %316, label %327, label %317
317: ; preds = %314
%318 = getelementptr inbounds i8, i8* %11, i64 %315
%319 = load i8, i8* %318
%320 = zext i8 %319 to i32
%321 = and i32 %280, %320
%322 = icmp eq i32 %321, 0
br i1 %322, label %327, label %323
323: ; preds = %317
%324 = getelementptr inbounds i8, i8* %0, i64 %315
%325 = load i8, i8* %324
%326 = xor i8 %325, 1
store i8 %326, i8* %324
br label %327
327: ; preds = %314, %323, %317, %278, %276
%328 = phi i32 [ 7, %276 ], [ %279, %278 ], [ %279, %317 ], [ %279, %323 ], [ %279, %314 ]
ret i32 %328
}