#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
unsigned int rangobits(unsigned int n, int bitmenor, int bitmayor) {
  unsigned int d1 = 1, d2 = 1;
  if (bitmenor < 0 || bitmenor > 31) {
    fprintf(stderr, "rangobits: Error en bitmenor: %d\n", bitmenor);
    exit(-1);
  } else if (bitmayor < 0 || bitmayor > 31) {
    fprintf(stderr, "rangobits: Error en bitmayor: %d\n", bitmayor);
    exit(-1);
  } else if (bitmayor < bitmenor) {
    fprintf(stderr, "rangobits: Error en orden\n");
    exit(-1);
  } else if (bitmayor - bitmenor + 1 < 32) {
    d1 = d1 << bitmenor;
    d2 = d2 << (bitmayor - bitmenor + 1);
    n = n / d1;
    n = n % d2;
  }
  return n;
}


x86 assembly (clang, -O0):
<rangobits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1153 <rangobits+0x33>
cmpl   $0x1f,-0x8(%rbp)
jle    1177 <rangobits+0x57>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe9a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
jl     118b <rangobits+0x6b>
cmpl   $0x1f,-0xc(%rbp)
jle    11af <rangobits+0x8f>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11dc <rangobits+0xbc>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
mov    -0xc(%rbp),%eax
sub    -0x8(%rbp),%eax
add    $0x1,%eax
cmp    $0x20,%eax
jge    1220 <rangobits+0x100>
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    -0x8(%rbp),%ecx
add    $0x1,%ecx
shl    %cl,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x10(%rbp)
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x14(%rbp)
mov    %edx,-0x4(%rbp)
jmp    1225 <rangobits+0x105>
jmp    122a <rangobits+0x10a>
jmp    122f <rangobits+0x10f>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rangobits>:
push   %rax
mov    %esi,%ecx
cmp    $0x20,%esi
jae    114c <rangobits+0x2c>
cmp    $0x20,%edx
jae    1160 <rangobits+0x40>
sub    %ecx,%edx
jb     1181 <rangobits+0x61>
cmp    $0x1e,%edx
jg     1148 <rangobits+0x28>
shr    %cl,%edi
add    $0x1,%dl
mov    $0xffffffff,%eax
mov    %edx,%ecx
shl    %cl,%eax
not    %eax
and    %eax,%edi
mov    %edi,%eax
pop    %rcx
ret
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
mov    %ecx,%edx
jmp    1170 <rangobits+0x50>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xeb2(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xeb3(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"rangobits: Error en bitmenor: %d\0A\00"
@.str.1 = [34 x i8] c"rangobits: Error en bitmayor: %d\0A\00"
@.str.2 = [27 x i8] c"rangobits: Error en orden\0A\00"
define i32 @rangobits(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 1, i32* %7
store i32 1, i32* %8
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load i32, i32* %5
%13 = icmp sgt i32 %12, 31
br i1 %13, label %14, label %19
14: ; preds = %11, %3
%15 = load i32, i32* @stderr
%16 = load i32, i32* %5
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %11
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* %6
%24 = icmp sgt i32 %23, 31
br i1 %24, label %25, label %30
25: ; preds = %22, %19
%26 = load i32, i32* @stderr
%27 = load i32, i32* %6
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %22
%31 = load i32, i32* %6
%32 = load i32, i32* %5
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 -1)
unreachable
38: ; preds = %30
%39 = load i32, i32* %6
%40 = load i32, i32* %5
%41 = sub nsw i32 %39, %40
%42 = add nsw i32 %41, 1
%43 = icmp slt i32 %42, 32
br i1 %43, label %44, label %60
44: ; preds = %38
%45 = load i32, i32* %7
%46 = load i32, i32* %5
%47 = shl i32 %45, %46
store i32 %47, i32* %7
%48 = load i32, i32* %8
%49 = load i32, i32* %6
%50 = load i32, i32* %5
%51 = sub nsw i32 %49, %50
%52 = add nsw i32 %51, 1
%53 = shl i32 %48, %52
store i32 %53, i32* %8
%54 = load i32, i32* %4
%55 = load i32, i32* %7
%56 = udiv i32 %54, %55
store i32 %56, i32* %4
%57 = load i32, i32* %4
%58 = load i32, i32* %8
%59 = urem i32 %57, %58
store i32 %59, i32* %4
br label %60
60: ; preds = %44, %38
br label %61
61: ; preds = %60
br label %62
62: ; preds = %61
br label %63
63: ; preds = %62
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"rangobits: Error en bitmenor: %d\0A\00"
@.str.1 = [34 x i8] c"rangobits: Error en bitmayor: %d\0A\00"
@.str.2 = [27 x i8] c"rangobits: Error en orden\0A\00"
define i32 @rangobits(i32 %0, i32 %1, i32 %2) {
%4 = icmp ugt i32 %1, 31
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %1)
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %3
%10 = icmp ugt i32 %2, 31
br i1 %10, label %11, label %15
11: ; preds = %9
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %9
%16 = icmp ult i32 %2, %1
br i1 %16, label %17, label %21
17: ; preds = %15
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @exit(i32 -1)
unreachable
21: ; preds = %15
%22 = sub nsw i32 %2, %1
%23 = icmp slt i32 %22, 31
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = add nsw i32 %22, 1
%26 = lshr i32 %0, %1
%27 = shl nsw i32 -1, %25
%28 = xor i32 %27, -1
%29 = and i32 %26, %28
br label %30
30: ; preds = %21, %24
%31 = phi i32 [ %29, %24 ], [ %0, %21 ]
ret i32 %31
}