#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 */
scalar_t__ atol(char *);
int /*<<< orphan*/ hailstone(unsigned long);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int i;
  unsigned long n;
  if (argc > 2) {
    for (i = 1; i < argc; i++) {
      n = (unsigned long)atol(argv[i]);
      printf("%lu\n", n);
      hailstone(n);
    }
  } else if (argc == 2) {
    unsigned long k, l;
    l = (unsigned long)atol(argv[1]);
    for (k = 1; k < l; k++) {
      hailstone(k);
    }
  } else {
    printf("usage: hailstone n [m ...]\n");
    printf("If only n is given, runs all integers in [1..n]\n");
    printf("If n, m, ... are given, runs each [n, m, ...]\n");
  }
  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)
cmpl   $0x2,-0x8(%rbp)
jle    11a6 <main+0x76>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a1 <main+0x71>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <atol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <hailstone@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1157 <main+0x27>
jmp    1225 <main+0xf5>
cmpl   $0x2,-0x8(%rbp)
jne    11f6 <main+0xc6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atol@plt>
mov    %rax,-0x30(%rbp)
movq   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    11f1 <main+0xc1>
mov    -0x28(%rbp),%rdi
call   1040 <hailstone@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11c9 <main+0x99>
jmp    1220 <main+0xf0>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1225 <main+0xf5>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
cmp    $0x3,%edi
jl     118c <main+0x4c>
mov    %edi,%r12d
mov    $0x1,%ebx
lea    0xea0(%rip),%r14
mov    (%r15,%rbx,8),%rdi
call   1060 <atol@plt>
mov    %rax,%r13
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
call   1050 <hailstone@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <main+0x20>
jmp    11e7 <main+0xa7>
cmp    $0x2,%edi
jne    11c3 <main+0x83>
mov    0x8(%r15),%rdi
call   1060 <atol@plt>
cmp    $0x2,%rax
jb     11e7 <main+0xa7>
mov    %rax,%r14
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <hailstone@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11b0 <main+0x70>
jmp    11e7 <main+0xa7>
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lu\0A\00"
@.str.1 = [28 x i8] c"usage: hailstone n [m ...]\0A\00"
@.str.2 = [49 x i8] c"If only n is given, runs all integers in [1..n]\0A\00"
@.str.3 = [47 x i8] c"If n, m, ... are given, runs each [n, m, ...]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 2
br i1 %11, label %12, label %32
12: ; preds = %2
store i32 1, i32* %6
br label %13
13: ; preds = %28, %12
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %31
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = call i64 @atol(i8* %22)
store i64 %23, i64* %7
%24 = load i64, i64* %7
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %24)
%26 = load i64, i64* %7
%27 = call i32 @hailstone(i64 %26)
br label %28
28: ; preds = %17
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %13
31: ; preds = %13
br label %56
32: ; preds = %2
%33 = load i32, i32* %4
%34 = icmp eq i32 %33, 2
br i1 %34, label %35, label %51
35: ; preds = %32
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i64 @atol(i8* %38)
store i64 %39, i64* %9
store i64 1, i64* %8
br label %40
40: ; preds = %47, %35
%41 = load i64, i64* %8
%42 = load i64, i64* %9
%43 = icmp ult i64 %41, %42
br i1 %43, label %44, label %50
44: ; preds = %40
%45 = load i64, i64* %8
%46 = call i32 @hailstone(i64 %45)
br label %47
47: ; preds = %44
%48 = load i64, i64* %8
%49 = add i64 %48, 1
store i64 %49, i64* %8
br label %40
50: ; preds = %40
br label %55
51: ; preds = %32
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
br label %55
55: ; preds = %51, %50
br label %56
56: ; preds = %55, %31
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lu\0A\00"
@str = [27 x i8] c"usage: hailstone n [m ...]\00"
@str.4 = [48 x i8] c"If only n is given, runs all integers in [1..n]\00"
@str.5 = [46 x i8] c"If n, m, ... are given, runs each [n, m, ...]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 2
br i1 %3, label %4, label %15
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 1, %4 ], [ %13, %6 ]
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i64 @atol(i8* %9)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %10)
%12 = tail call i32 @hailstone(i64 %10)
%13 = add nuw nsw i64 %7, 1
%14 = icmp eq i64 %13, %5
br i1 %14, label %31, label %6
15: ; preds = %2
%16 = icmp eq i32 %0, 2
br i1 %16, label %17, label %27
17: ; preds = %15
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i64 @atol(i8* %19)
%21 = icmp ugt i64 %20, 1
br i1 %21, label %22, label %31
22: ; preds = %17, %22
%23 = phi i64 [ %25, %22 ], [ 1, %17 ]
%24 = tail call i32 @hailstone(i64 %23)
%25 = add nuw i64 %23, 1
%26 = icmp eq i64 %25, %20
br i1 %26, label %31, label %22
27: ; preds = %15
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.4, i64 0, i64 0))
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.5, i64 0, i64 0))
br label %31
31: ; preds = %22, %6, %17, %27
ret i32 0
}