#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*/ printf(char *, int, int, int);
int gen_mask(int m, int n) {
  int mask = 0, mask1, mask2;
  if (m < 31)
    mask1 = ((1 << (m + 1)) - 1);
  else
    mask1 = 0;
  mask2 = (~((1 << n) - 1));
  printf("%x mask1 = %x mask2 = %x\n", 1 << (m + 1), mask1, mask2);
  mask = mask1 & mask2;
  return mask;
}


x86 assembly (clang, -O0):
<gen_mask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x1f,-0x4(%rbp)
jge    1147 <gen_mask+0x37>
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114e <gen_mask+0x3e>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
sub    $0x1,%eax
xor    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
mov    $0x1,%esi
shl    %cl,%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
and    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_mask>:
push   %rbp
push   %rbx
push   %rax
lea    0x1(%rdi),%eax
mov    $0xffffffff,%ebx
mov    %eax,%ecx
shl    %cl,%ebx
xor    %ecx,%ecx
cmp    $0x1f,%edi
not    %ebx
cmovge %ecx,%ebx
mov    $0xffffffff,%ebp
mov    %esi,%ecx
shl    %cl,%ebp
mov    $0x1,%esi
mov    %eax,%ecx
shl    %cl,%esi
lea    0xebe(%rip),%rdi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1030 <printf@plt>
and    %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"%x mask1 = %x mask2 = %x\0A\00"
define i32 @gen_mask(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 31
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
%13 = shl i32 1, %12
%14 = sub nsw i32 %13, 1
store i32 %14, i32* %6
br label %16
15: ; preds = %2
store i32 0, i32* %6
br label %16
16: ; preds = %15, %10
%17 = load i32, i32* %4
%18 = shl i32 1, %17
%19 = sub nsw i32 %18, 1
%20 = xor i32 %19, -1
store i32 %20, i32* %7
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
%23 = shl i32 1, %22
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %24, i32 %25)
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = and i32 %27, %28
store i32 %29, i32* %5
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
@.str = [26 x i8] c"%x mask1 = %x mask2 = %x\0A\00"
define i32 @gen_mask(i32 %0, i32 %1) {
%3 = icmp slt i32 %0, 31
%4 = add nsw i32 %0, 1
%5 = shl nsw i32 -1, %4
%6 = xor i32 %5, -1
%7 = select i1 %3, i32 %6, i32 0
%8 = shl nsw i32 -1, %1
%9 = shl nuw i32 1, %4
%10 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %7, i32 %8)
%11 = and i32 %7, %8
ret i32 %11
}