int main(argc, argv)
int argc;
char *argv[];
{
  long i, n, flag = 0;
  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    1187 <main+0x47>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x0,%al
call   1040 <atol@plt>
cltq
mov    %rax,-0x20(%rbp)
cmp    $0x2,%rax
jge    119f <main+0x5f>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpq   $0x2,-0x20(%rbp)
jne    11bf <main+0x7f>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
jmp    11c4 <main+0x84>
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1060 <first@plt>
cltq
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121b <main+0xdb>
cmpq   $0x0,-0x28(%rbp)
jne    1202 <main+0xc2>
mov    -0x20(%rbp),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1214 <main+0xd4>
mov    -0x20(%rbp),%rsi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xe21(%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    11c4 <main+0x84>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edi
jne    116d <main+0x1d>
mov    0x8(%rsi),%rdi
xor    %eax,%eax
call   1050 <atol@plt>
cmp    $0x1,%eax
jg     1183 <main+0x33>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmp    $0x2,%eax
jne    119b <main+0x4b>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    %eax,%r12d
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <first@plt>
test   %eax,%eax
jne    11b5 <main+0x65>
lea    0xe4d(%rip),%rdi
jmp    1228 <main+0xd8>
mov    %eax,%r14d
lea    0xe56(%rip),%r15
mov    %eax,%ebp
jmp    11eb <main+0x9b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rax
cqto
idiv   %rbx
mov    %rax,%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <first@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1213 <main+0xc3>
movslq %ebp,%rbx
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    %ebp
mov    %eax,%r12d
jmp    11db <main+0x8b>
test   %r14d,%r14d
lea    0xde3(%rip),%rax
lea    0xdec(%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 %18, 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 i32 (i8*, ...) bitcast (i32 (...)* @atol to i32 (i8*, ...)*)(i8* %14)
%16 = sext i32 %15 to i64
store i64 %16, i64* %7
%17 = icmp slt i64 %16, 2
br i1 %17, label %18, label %20
18: ; preds = %11, %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
unreachable
20: ; preds = %11
%21 = load i64, i64* %7
%22 = icmp eq i64 %21, 2
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
unreachable
25: ; preds = %20
br label %26
26: ; preds = %25, %42
%27 = load i64, i64* %7
%28 = call i32 (i64, ...) bitcast (i32 (...)* @first to i32 (i64, ...)*)(i64 %27)
%29 = sext i32 %28 to i64
store i64 %29, i64* %6
%30 = load i64, i64* %6
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %26
%33 = load i64, i64* %8
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i64, i64* %7
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64 %36)
br label %41
38: ; preds = %32
%39 = load i64, i64* %7
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %39)
br label %41
41: ; preds = %38, %35
unreachable
42: ; preds = %26
%43 = load i64, i64* %6
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %43)
%45 = load i64, i64* %7
%46 = load i64, i64* %6
%47 = sdiv i64 %45, %46
store i64 %47, i64* %7
store i64 1, i64* %8
br label %26
}

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 i32 (i8*, ...) bitcast (i32 (...)* @atol to i32 (i8*, ...)*)(i8* %6)
%8 = icmp slt i32 %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 = zext i32 %7 to i64
%13 = icmp eq i32 %7, 2
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = tail call i32 (i64, ...) bitcast (i32 (...)* @first to i32 (i64, ...)*)(i64 %12)
%16 = icmp eq i32 %15, 0
br i1 %16, label %21, label %25
17: ; preds = %11
%18 = 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
19: ; preds = %25
%20 = select i1 %16, 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 %21
21: ; preds = %19, %14
%22 = phi i64 [ %12, %14 ], [ %30, %19 ]
%23 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), %14 ], [ %20, %19 ]
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %23, i64 %22)
tail call void @exit(i32 0)
unreachable
25: ; preds = %14, %25
%26 = phi i32 [ %31, %25 ], [ %15, %14 ]
%27 = phi i64 [ %30, %25 ], [ %12, %14 ]
%28 = sext i32 %26 to i64
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %28)
%30 = sdiv i64 %27, %28
%31 = tail call i32 (i64, ...) bitcast (i32 (...)* @first to i32 (i64, ...)*)(i64 %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %19, label %25
}