#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned long);
unsigned long strtol(char const *, char **, int);
int main(int argc, const char *argv[]) {
  char *end;
  unsigned long num = strtol(argv[1], &end, 10);
  unsigned long largest_prime = 2;
  if (argc == 2) {
    while (num != 1) {
      if (num % largest_prime == 0)
        num /= largest_prime;
      else
        largest_prime++;
    }
  } else {
    exit(EXIT_FAILURE);
  }
  printf("Largest prime is: %ld\n", largest_prime);
  return 0;
}


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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
movq   $0x2,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11c4 <main+0x94>
jmp    1177 <main+0x47>
cmpq   $0x1,-0x20(%rbp)
je     11bf <main+0x8f>
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x28(%rbp)
cmp    $0x0,%rdx
jne    11ae <main+0x7e>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
jmp    11ba <main+0x8a>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1177 <main+0x47>
jmp    11d2 <main+0xa2>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x28(%rbp),%rsi
lea    0xe23(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
cmp    $0x2,%ebx
jne    11a5 <main+0x75>
mov    %rax,%rcx
mov    $0x2,%esi
jmp    1177 <main+0x47>
nopl   0x0(%rax)
mov    %rcx,%rax
xor    %edx,%edx
div    %rsi
test   %rdx,%rdx
cmove  %rax,%rcx
lea    0x1(%rsi),%rax
cmovne %rax,%rsi
cmp    $0x1,%rcx
je     1191 <main+0x61>
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
jne    1160 <main+0x30>
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
jmp    1168 <main+0x38>
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [23 x i8] c"Largest prime is: %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i64 @strtol(i8* %11, i8** %6, i32 10)
store i64 %12, i64* %7
store i64 2, i64* %8
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %33
15: ; preds = %2
br label %16
16: ; preds = %31, %15
%17 = load i64, i64* %7
%18 = icmp ne i64 %17, 1
br i1 %18, label %19, label %32
19: ; preds = %16
%20 = load i64, i64* %7
%21 = load i64, i64* %8
%22 = urem i64 %20, %21
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = load i64, i64* %8
%26 = load i64, i64* %7
%27 = udiv i64 %26, %25
store i64 %27, i64* %7
br label %31
28: ; preds = %19
%29 = load i64, i64* %8
%30 = add i64 %29, 1
store i64 %30, i64* %8
br label %31
31: ; preds = %28, %24
br label %16
32: ; preds = %16
br label %36
33: ; preds = %2
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %32
%37 = load i64, i64* %8
%38 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i64 %37)
ret i32 0
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [23 x i8] c"Largest prime is: %ld\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = call i64 @strtol(i8* %6, i8** %3, i32 10)
%8 = icmp eq i32 %0, 2
br i1 %8, label %9, label %21
9: ; preds = %2
%10 = icmp eq i64 %7, 1
br i1 %10, label %24, label %11
11: ; preds = %9, %11
%12 = phi i64 [ %19, %11 ], [ 2, %9 ]
%13 = phi i64 [ %18, %11 ], [ %7, %9 ]
%14 = urem i64 %13, %12
%15 = udiv i64 %13, %12
%16 = icmp eq i64 %14, 0
%17 = add i64 %12, 1
%18 = select i1 %16, i64 %15, i64 %13
%19 = select i1 %16, i64 %12, i64 %17
%20 = icmp eq i64 %18, 1
br i1 %20, label %24, label %11
21: ; preds = %2
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %11, %9
%25 = phi i64 [ 2, %9 ], [ %19, %11 ]
%26 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i64 %25)
ret i32 0
}