#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 gauss_map(unsigned long, unsigned long);
int /*<<< orphan*/ printf(char *, unsigned long, unsigned long, unsigned long,
                          int);
void print_quotient_rest(unsigned long n) {
  unsigned long p, r, q, rr;
  for (p = 1; p < n; ++p) {
    q = n / p;
    r = n % p;
    rr = (r * r) / p;
    if (2 * ((r * r) % p) > p)
      rr += 1;
    printf("%3d %3d %3d %3d\n", p, q, rr, gauss_map(p, n));
  }
}


x86 assembly (clang, -O0):
<print_quotient_rest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11f3 <print_quotient_rest+0xd3>
mov    -0x8(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x18(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x18(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
shl    $0x1,%rdx
cmp    -0x10(%rbp),%rdx
jbe    11a2 <print_quotient_rest+0x82>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <gauss_map@plt>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    %eax,%r8d
lea    0xe23(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <print_quotient_rest+0x14>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_quotient_rest>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x2,%rdi
jb     11d5 <print_quotient_rest+0xb5>
mov    %rdi,%r14
mov    $0x1,%ebx
lea    0xebe(%rip),%r15
jmp    118d <print_quotient_rest+0x6d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rdx,%rax
xor    %edx,%edx
div    %rbx
mov    %rax,%r13
add    %rdx,%rdx
cmp    %rdx,%rbx
adc    $0x0,%r13
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <gauss_map@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %eax,%r8d
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
je     11d5 <print_quotient_rest+0xb5>
mov    %r14,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     11b0 <print_quotient_rest+0x90>
mov    %r14,%rax
xor    %edx,%edx
div    %rbx
mov    %rax,%r12
jmp    11ba <print_quotient_rest+0x9a>
cs nopw 0x0(%rax,%rax,1)
mov    %r14d,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%r12d
imul   %rdx,%rdx
mov    %rdx,%rax
or     %rbx,%rax
shr    $0x20,%rax
jne    1150 <print_quotient_rest+0x30>
mov    %edx,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%r13d
jmp    115b <print_quotient_rest+0x3b>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [17 x i8] c"%3d %3d %3d %3d\0A\00"
define void @print_quotient_rest(i64 %0) {
%2 = icmp ugt i64 %0, 1
br i1 %2, label %3, label %18
3: ; preds = %1, %3
%4 = phi i64 [ %16, %3 ], [ 1, %1 ]
%5 = udiv i64 %0, %4
%6 = urem i64 %0, %4
%7 = mul i64 %6, %6
%8 = udiv i64 %7, %4
%9 = urem i64 %7, %4
%10 = shl i64 %9, 1
%11 = icmp ugt i64 %10, %4
%12 = zext i1 %11 to i64
%13 = add i64 %8, %12
%14 = tail call i32 @gauss_map(i64 %4, i64 %0)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %4, i64 %5, i64 %13, i32 %14)
%16 = add nuw i64 %4, 1
%17 = icmp eq i64 %16, %0
br i1 %17, label %18, label %3
18: ; preds = %3, %1
ret void
}