main(argc, argv) int argc;
char *argv[];
{
  long i, n, flag = 0, first(), atol();
  if (argc != 2 || (n = atol(argv[1])) < 2) {
    printf("Usage: factor n   (2 <= n < 2**31)\n");
    exit(1);
  }
  if (n == 2) {
    printf("2 is a prime\n");
    exit(0);
  }
  while (1) {
    i = first(n);
    if (i == 0) {
      if (flag == 0)
        printf("%ld is a prime\n", n);
      else
        printf("%ld\n", n);
      exit(0);
    }
    printf("%ld ", i);
    n = n / i;
    flag = 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1185 <main+0x45>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x0,%al
call   1040 <atol@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x2,%rax
jge    119d <main+0x5d>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpq   $0x2,-0x20(%rbp)
jne    11bd <main+0x7d>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
jmp    11c2 <main+0x82>
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1060 <first@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1217 <main+0xd7>
cmpq   $0x0,-0x28(%rbp)
jne    11fe <main+0xbe>
mov    -0x20(%rbp),%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1210 <main+0xd0>
mov    -0x20(%rbp),%rsi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
cqto
idivq  -0x18(%rbp)
mov    %rax,-0x20(%rbp)
movq   $0x1,-0x28(%rbp)
jmp    11c2 <main+0x82>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    116e <main+0x1e>
mov    0x8(%rsi),%rdi
xor    %eax,%eax
call   1050 <atol@plt>
cmp    $0x1,%rax
jg     1184 <main+0x34>
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    %rax,%r12
cmp    $0x2,%rax
jne    11a0 <main+0x50>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <first@plt>
test   %rax,%rax
jne    11b8 <main+0x68>
lea    0xe4a(%rip),%rdi
jmp    1227 <main+0xd7>
mov    %rax,%r14
lea    0xe53(%rip),%r15
mov    %rax,%rbx
jmp    11ed <main+0x9d>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rax
cqto
idiv   %rbx
mov    %rax,%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <first@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1212 <main+0xc2>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rax
or     %rbx,%rax
shr    $0x20,%rax
jne    11d0 <main+0x80>
mov    %r12d,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%r12d
jmp    11db <main+0x8b>
test   %r14,%r14
lea    0xde4(%rip),%rax
lea    0xded(%rip),%rdi
cmove  %rax,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"Usage: factor n (2 <= n < 2**31)\0A\00"
@.str.1 = [14 x i8] c"2 is a prime\0A\00"
@.str.2 = [16 x i8] c"%ld is a prime\0A\00"
@.str.3 = [5 x i8] c"%ld\0A\00"
@.str.4 = [5 x i8] c"%ld \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %17, label %11
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 (i8*, ...) bitcast (i64 (...)* @atol to i64 (i8*, ...)*)(i8* %14)
store i64 %15, i64* %7
%16 = icmp slt i64 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %11, %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
unreachable
19: ; preds = %11
%20 = load i64, i64* %7
%21 = icmp eq i64 %20, 2
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
unreachable
24: ; preds = %19
br label %25
25: ; preds = %24, %40
%26 = load i64, i64* %7
%27 = call i64 (i64, ...) bitcast (i64 (...)* @first to i64 (i64, ...)*)(i64 %26)
store i64 %27, i64* %6
%28 = load i64, i64* %6
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %25
%31 = load i64, i64* %8
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i64, i64* %7
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64 %34)
br label %39
36: ; preds = %30
%37 = load i64, i64* %7
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %37)
br label %39
39: ; preds = %36, %33
unreachable
40: ; preds = %25
%41 = load i64, i64* %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %41)
%43 = load i64, i64* %7
%44 = load i64, i64* %6
%45 = sdiv i64 %43, %44
store i64 %45, i64* %7
store i64 1, i64* %8
br label %25
}

LLVM IR (-O2):
@.str.2 = [16 x i8] c"%ld is a prime\0A\00"
@.str.3 = [5 x i8] c"%ld\0A\00"
@.str.4 = [5 x i8] c"%ld \00"
@str = [13 x i8] c"2 is a prime\00"
@str.5 = [35 x i8] c"Usage: factor n (2 <= n < 2**31)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 (i8*, ...) bitcast (i64 (...)* @atol to i64 (i8*, ...)*)(i8* %6)
%8 = icmp slt i64 %7, 2
br i1 %8, label %9, label %11
9: ; preds = %4, %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.5, i64 0, i64 0))
tail call void @exit(i32 1)
unreachable
11: ; preds = %4
%12 = icmp eq i64 %7, 2
br i1 %12, label %16, label %13
13: ; preds = %11
%14 = tail call i64 (i64, ...) bitcast (i64 (...)* @first to i64 (i64, ...)*)(i64 %7)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %24
16: ; preds = %11
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
tail call void @exit(i32 0)
unreachable
18: ; preds = %24
%19 = select i1 %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
br label %20
20: ; preds = %18, %13
%21 = phi i64 [ %7, %13 ], [ %28, %18 ]
%22 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), %13 ], [ %19, %18 ]
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %22, i64 %21)
tail call void @exit(i32 0)
unreachable
24: ; preds = %13, %24
%25 = phi i64 [ %29, %24 ], [ %14, %13 ]
%26 = phi i64 [ %28, %24 ], [ %7, %13 ]
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %25)
%28 = sdiv i64 %26, %25
%29 = tail call i64 (i64, ...) bitcast (i64 (...)* @first to i64 (i64, ...)*)(i64 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %18, label %24
}