#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*/ free(unsigned char *);
unsigned char *hash_trunc(int);
int ucharToInt(unsigned char *, int);
int uniform_m2e(int s, int module) {
  int res;
  unsigned char *aux;
  while (1) {
    aux = hash_trunc(s);
    res = ucharToInt(aux, s);
    if (res > ((1 << (s * 8)) - ((1 << (s * 8)) % module))) {
      free(aux);
      continue;
    }
    free(aux);
    return res % module;
  }
}


x86 assembly (clang, -O0):
<uniform_m2e>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <hash_trunc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1050 <ucharToInt@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%ecx
shl    $0x3,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%ecx
shl    $0x3,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    -0x20(%rbp),%ecx
cltd
idivl  -0x8(%rbp)
mov    -0x1c(%rbp),%eax
sub    %edx,%ecx
cmp    %ecx,%eax
jle    119e <uniform_m2e+0x6e>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    113e <uniform_m2e+0xe>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %edx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uniform_m2e>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %edi,%r15d
call   1040 <hash_trunc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15d,%esi
call   1050 <ucharToInt@plt>
mov    %eax,%ebp
lea    0x0(,%r15,8),%ecx
mov    $0x1,%r12d
shl    %cl,%r12d
mov    %r12d,%eax
cltd
idiv   %r14d
sub    %edx,%r12d
cmp    %r12d,%ebp
jle    11a5 <uniform_m2e+0x75>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15d,%edi
call   1040 <hash_trunc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15d,%esi
call   1050 <ucharToInt@plt>
cmp    %r12d,%eax
jg     1180 <uniform_m2e+0x50>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
cltd
idiv   %r14d
mov    %edx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @uniform_m2e(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
br label %7
7: ; preds = %2, %24
%8 = load i32, i32* %3
%9 = call i8* @hash_trunc(i32 %8)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = load i32, i32* %3
%12 = call i32 @ucharToInt(i8* %10, i32 %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = load i32, i32* %3
%15 = mul nsw i32 %14, 8
%16 = shl i32 1, %15
%17 = load i32, i32* %3
%18 = mul nsw i32 %17, 8
%19 = shl i32 1, %18
%20 = load i32, i32* %4
%21 = srem i32 %19, %20
%22 = sub nsw i32 %16, %21
%23 = icmp sgt i32 %13, %22
br i1 %23, label %24, label %27
24: ; preds = %7
%25 = load i8*, i8** %6
%26 = call i32 @free(i8* %25)
br label %7
27: ; preds = %7
%28 = load i8*, i8** %6
%29 = call i32 @free(i8* %28)
%30 = load i32, i32* %5
%31 = load i32, i32* %4
%32 = srem i32 %30, %31
ret i32 %32
}

LLVM IR (-O2):
define i32 @uniform_m2e(i32 %0, i32 %1) {
%3 = tail call i8* @hash_trunc(i32 %0)
%4 = tail call i32 @ucharToInt(i8* %3, i32 %0)
%5 = shl nsw i32 %0, 3
%6 = shl nuw i32 1, %5
%7 = srem i32 %6, %1
%8 = sub nsw i32 %6, %7
%9 = icmp sgt i32 %4, %8
br i1 %9, label %10, label %16
10: ; preds = %2, %10
%11 = phi i8* [ %13, %10 ], [ %3, %2 ]
%12 = tail call i32 @free(i8* %11)
%13 = tail call i8* @hash_trunc(i32 %0)
%14 = tail call i32 @ucharToInt(i8* %13, i32 %0)
%15 = icmp sgt i32 %14, %8
br i1 %15, label %10, label %16
16: ; preds = %10, %2
%17 = phi i8* [ %3, %2 ], [ %13, %10 ]
%18 = phi i32 [ %4, %2 ], [ %14, %10 ]
%19 = tail call i32 @free(i8* %17)
%20 = srem i32 %18, %1
ret i32 %20
}