#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 factors(unsigned n) {
  if (n == 0)
    return;
  printf("factors of %u:\n", n);
  unsigned a = 1, b = n;
  while (a <= b) {
    if (a * b == n)
      printf("%u, %u\n", a, b);
    a++;
    b = n / a;
  }
}


x86 assembly (clang, -O0):
<factors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    112a <factors+0x1a>
jmp    1191 <factors+0x81>
mov    -0x4(%rbp),%esi
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
ja     1191 <factors+0x81>
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    1178 <factors+0x68>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,-0xc(%rbp)
jmp    1148 <factors+0x38>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factors>:
push   %rbp
push   %r14
push   %rbx
test   %edi,%edi
je     1166 <factors+0x56>
mov    %edi,%ebx
lea    0xedf(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebp
lea    0xeda(%rip),%r14
mov    %ebx,%eax
jmp    114d <factors+0x3d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
cmp    %eax,%ebp
ja     1166 <factors+0x56>
mov    %eax,%ecx
imul   %ebp,%ecx
cmp    %ebx,%ecx
jne    1140 <factors+0x30>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1140 <factors+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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