#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 */
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
scalar_t__ mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_div_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
scalar_t__ mpz_even_p(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_str(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ mpz_mul_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int main(int ac, char *av[]) {
  mpz_t n, n2, min_n, max_n;
  if (ac < 3) {
    printf("usage : collatz min_n max_n\n");
    return (1);
  }
  mpz_init_set_str(min_n, av[1], 10);
  mpz_init_set_str(max_n, av[2], 10);
  mpz_init_set(n, min_n);
  while (mpz_cmp(n, max_n) <= 0) {
    mpz_init_set(n2, n);
    while (mpz_cmp(n2, n) >= 0) {
      if (mpz_even_p(n2)) {
        mpz_div_ui(n2, n2, 2);
      } else {
        mpz_mul_ui(n2, n2, 3);
        mpz_add_ui(n2, n2, 1);
        mpz_div_ui(n2, n2, 2);
      }
    }
    mpz_add_ui(n, n, 2);
  }
  mpz_clear(n);
  mpz_clear(n2);
  mpz_clear(max_n);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11c8 <main+0x38>
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c2 <main+0x132>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0xa,%edx
call   1060 <mpz_init_set_str@plt>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    $0xa,%edx
call   1060 <mpz_init_set_str@plt>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   10a0 <mpz_init_set@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1080 <mpz_cmp@plt>
cmp    $0x0,%rax
jg     12a3 <main+0x113>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   10a0 <mpz_init_set@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1080 <mpz_cmp@plt>
cmp    $0x0,%rax
jl     128e <main+0xfe>
mov    -0x18(%rbp),%edi
call   1070 <mpz_even_p@plt>
cmp    $0x0,%rax
je     1259 <main+0xc9>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x2,%edx
call   1030 <mpz_div_ui@plt>
jmp    1289 <main+0xf9>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x3,%edx
call   10b0 <mpz_mul_ui@plt>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x1,%edx
call   1040 <mpz_add_ui@plt>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x2,%edx
call   1030 <mpz_div_ui@plt>
jmp    121d <main+0x8d>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    $0x2,%edx
call   1040 <mpz_add_ui@plt>
jmp    11fd <main+0x6d>
mov    -0x14(%rbp),%edi
call   1090 <mpz_clear@plt>
mov    -0x18(%rbp),%edi
call   1090 <mpz_clear@plt>
mov    -0x20(%rbp),%edi
call   1090 <mpz_clear@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jg     11a9 <main+0x19>
lea    0xe63(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
mov    $0xa,%edx
call   1060 <mpz_init_set_str@plt>
mov    0x10(%rbx),%rsi
mov    $0xa,%edx
call   1060 <mpz_init_set_str@plt>
call   10a0 <mpz_init_set@plt>
jmp    11da <main+0x4a>
nop
mov    $0x2,%edx
call   1050 <mpz_add_ui@plt>
call   1080 <mpz_cmp@plt>
test   %rax,%rax
jg     1224 <main+0x94>
call   10a0 <mpz_init_set@plt>
jmp    11fa <main+0x6a>
nopl   0x0(%rax,%rax,1)
mov    $0x2,%edx
call   1030 <mpz_div_ui@plt>
call   1080 <mpz_cmp@plt>
test   %rax,%rax
js     11d0 <main+0x40>
call   1070 <mpz_even_p@plt>
test   %rax,%rax
jne    11f0 <main+0x60>
mov    $0x3,%edx
call   10b0 <mpz_mul_ui@plt>
mov    $0x1,%edx
call   1050 <mpz_add_ui@plt>
jmp    11f0 <main+0x60>
call   1090 <mpz_clear@plt>
call   1090 <mpz_clear@plt>
call   1090 <mpz_clear@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [29 x i8] c"usage : collatz min_n max_n\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %72
14: ; preds = %2
%15 = load i32, i32* %8
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @mpz_init_set_str(i32 %15, i8* %18, i32 10)
%20 = load i32, i32* %9
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @mpz_init_set_str(i32 %20, i8* %23, i32 10)
%25 = load i32, i32* %6
%26 = load i32, i32* %8
%27 = call i32 @mpz_init_set(i32 %25, i32 %26)
br label %28
28: ; preds = %61, %14
%29 = load i32, i32* %6
%30 = load i32, i32* %9
%31 = call i64 @mpz_cmp(i32 %29, i32 %30)
%32 = icmp sle i64 %31, 0
br i1 %32, label %33, label %65
33: ; preds = %28
%34 = load i32, i32* %7
%35 = load i32, i32* %6
%36 = call i32 @mpz_init_set(i32 %34, i32 %35)
br label %37
37: ; preds = %60, %33
%38 = load i32, i32* %7
%39 = load i32, i32* %6
%40 = call i64 @mpz_cmp(i32 %38, i32 %39)
%41 = icmp sge i64 %40, 0
br i1 %41, label %42, label %61
42: ; preds = %37
%43 = load i32, i32* %7
%44 = call i64 @mpz_even_p(i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i32, i32* %7
%48 = load i32, i32* %7
%49 = call i32 @mpz_div_ui(i32 %47, i32 %48, i32 2)
br label %60
50: ; preds = %42
%51 = load i32, i32* %7
%52 = load i32, i32* %7
%53 = call i32 @mpz_mul_ui(i32 %51, i32 %52, i32 3)
%54 = load i32, i32* %7
%55 = load i32, i32* %7
%56 = call i32 @mpz_add_ui(i32 %54, i32 %55, i32 1)
%57 = load i32, i32* %7
%58 = load i32, i32* %7
%59 = call i32 @mpz_div_ui(i32 %57, i32 %58, i32 2)
br label %60
60: ; preds = %50, %46
br label %37
61: ; preds = %37
%62 = load i32, i32* %6
%63 = load i32, i32* %6
%64 = call i32 @mpz_add_ui(i32 %62, i32 %63, i32 2)
br label %28
65: ; preds = %28
%66 = load i32, i32* %6
%67 = call i32 @mpz_clear(i32 %66)
%68 = load i32, i32* %7
%69 = call i32 @mpz_clear(i32 %68)
%70 = load i32, i32* %9
%71 = call i32 @mpz_clear(i32 %70)
store i32 0, i32* %3
br label %72
72: ; preds = %65, %12
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@str = [28 x i8] c"usage : collatz min_n max_n\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %38
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @mpz_init_set_str(i32 undef, i8* %8, i32 10)
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @mpz_init_set_str(i32 undef, i8* %11, i32 10)
%13 = tail call i32 @mpz_init_set(i32 undef, i32 undef)
%14 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%15 = icmp slt i64 %14, 1
br i1 %15, label %16, label %34
16: ; preds = %6, %30
%17 = tail call i32 @mpz_init_set(i32 undef, i32 undef)
%18 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%19 = icmp sgt i64 %18, -1
br i1 %19, label %20, label %30
20: ; preds = %16, %26
%21 = tail call i64 @mpz_even_p(i32 undef)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = tail call i32 @mpz_mul_ui(i32 undef, i32 undef, i32 3)
%25 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 1)
br label %26
26: ; preds = %20, %23
%27 = tail call i32 @mpz_div_ui(i32 undef, i32 undef, i32 2)
%28 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%29 = icmp sgt i64 %28, -1
br i1 %29, label %20, label %30
30: ; preds = %26, %16
%31 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 2)
%32 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%33 = icmp slt i64 %32, 1
br i1 %33, label %16, label %34
34: ; preds = %30, %6
%35 = tail call i32 @mpz_clear(i32 undef)
%36 = tail call i32 @mpz_clear(i32 undef)
%37 = tail call i32 @mpz_clear(i32 undef)
br label %38
38: ; preds = %34, %4
%39 = phi i32 [ 1, %4 ], [ 0, %34 ]
ret i32 %39
}