#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 *, unsigned int, ...);
void germainSanity(unsigned rem, unsigned div, unsigned order) {
  unsigned mul = 1;
  rem %= div;
  if (!rem)
    printf("bn div by %u!\n", div);
  while (order--) {
    rem += rem + 1;
    if (rem >= div)
      rem -= div;
    mul += mul;
    if (!rem)
      printf("%u*bn+%u div by %u!\n", mul, mul - 1, div);
  }
}


x86 assembly (clang, -O0):
<germainSanity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %edx,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1150 <germainSanity+0x40>
mov    -0x8(%rbp),%esi
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1155 <germainSanity+0x45>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     11be <germainSanity+0xae>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jb     118c <germainSanity+0x7c>
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11b9 <germainSanity+0xa9>
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
mov    -0x8(%rbp),%ecx
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1155 <germainSanity+0x45>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<germainSanity>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r14d
mov    %edi,%eax
xor    %edx,%edx
div    %esi
mov    %edx,%ebp
test   %edx,%edx
je     1134 <germainSanity+0x24>
test   %r15d,%r15d
jne    114a <germainSanity+0x3a>
jmp    1192 <germainSanity+0x82>
lea    0xec5(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
test   %r15d,%r15d
je     1192 <germainSanity+0x82>
mov    $0x1,%ebx
xor    %r13d,%r13d
lea    0xeb6(%rip),%r12
jmp    1165 <germainSanity+0x55>
nopl   0x0(%rax,%rax,1)
test   %r15d,%r15d
je     1192 <germainSanity+0x82>
add    $0xffffffff,%r15d
add    %ebp,%ebp
add    $0x1,%ebp
cmp    %r14d,%ebp
mov    %r14d,%eax
cmovb  %r13d,%eax
add    %ebx,%ebx
sub    %eax,%ebp
jne    1160 <germainSanity+0x50>
lea    -0x1(%rbx),%edx
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r14d,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1160 <germainSanity+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"bn div by %u!\0A\00"
@.str.1 = [21 x i8] c"%u*bn+%u div by %u!\0A\00"
define void @germainSanity(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 1, i32* %7
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = urem i32 %9, %8
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = load i32, i32* %5
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %13, %3
br label %17
17: ; preds = %45, %16
%18 = load i32, i32* %6
%19 = add i32 %18, -1
store i32 %19, i32* %6
%20 = icmp ne i32 %18, 0
br i1 %20, label %21, label %46
21: ; preds = %17
%22 = load i32, i32* %4
%23 = add i32 %22, 1
%24 = load i32, i32* %4
%25 = add i32 %24, %23
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = icmp uge i32 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %21
%30 = load i32, i32* %5
%31 = load i32, i32* %4
%32 = sub i32 %31, %30
store i32 %32, i32* %4
br label %33
33: ; preds = %29, %21
%34 = load i32, i32* %7
%35 = load i32, i32* %7
%36 = add i32 %35, %34
store i32 %36, i32* %7
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %33
%40 = load i32, i32* %7
%41 = load i32, i32* %7
%42 = sub i32 %41, 1
%43 = load i32, i32* %5
%44 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %40, i32 %42, i32 %43)
br label %45
45: ; preds = %39, %33
br label %17
46: ; preds = %17
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"bn div by %u!\0A\00"
@.str.1 = [21 x i8] c"%u*bn+%u div by %u!\0A\00"
define void @germainSanity(i32 %0, i32 %1, i32 %2) {
%4 = urem i32 %0, %1
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %8
8: ; preds = %6, %3
%9 = icmp eq i32 %2, 0
br i1 %9, label %27, label %10
10: ; preds = %8, %25
%11 = phi i32 [ %14, %25 ], [ %2, %8 ]
%12 = phi i32 [ %20, %25 ], [ 1, %8 ]
%13 = phi i32 [ %19, %25 ], [ %4, %8 ]
%14 = add i32 %11, -1
%15 = shl i32 %13, 1
%16 = or i32 %15, 1
%17 = icmp ult i32 %16, %1
%18 = select i1 %17, i32 0, i32 %1
%19 = sub i32 %16, %18
%20 = shl i32 %12, 1
%21 = icmp eq i32 %19, 0
br i1 %21, label %22, label %25
22: ; preds = %10
%23 = add i32 %20, -1
%24 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %23, i32 %1)
br label %25
25: ; preds = %22, %10
%26 = icmp eq i32 %14, 0
br i1 %26, label %27, label %10
27: ; preds = %25, %8
ret void
}