#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 atoi(char *);
int /*<<< orphan*/ printf(char *, float);
int main(int argc, char **argv) {
  const unsigned long N = argc > 1 ? 1000000 * atoi(argv[1]) : 2;
  unsigned long n;
  float x, xx, err = 0.0;
  for (n = 1; n < N; ++n) {
    x = n;
    while (x > 1.0) {
      xx = x / 2.0;
      if (xx - (unsigned long)(xx) > 0.25)
        x = 3.0 * x + 1.0;
      else
        x = xx;
    }
    err += x > 1.0 ? 1.0 - x : x - 1.0;
  }
  printf("err = %e\n", err);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    115b <main+0x3b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
imul   $0xf4240,%eax,%eax
mov    %eax,-0x30(%rbp)
jmp    1168 <main+0x48>
mov    $0x2,%eax
mov    %eax,-0x30(%rbp)
jmp    1168 <main+0x48>
mov    -0x30(%rbp),%eax
cltq
mov    %rax,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
movq   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    135a <main+0x23a>
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x38(%rbp)
test   %rax,%rax
movss  %xmm0,-0x34(%rbp)
js     11cc <main+0xac>
movss  -0x38(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe19(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12da <main+0x1ba>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe0e(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x44(%rbp)
movss  0xdff(%rip),%xmm2
movaps %xmm0,%xmm1
subss  %xmm2,%xmm1
cvttss2si %xmm1,%rcx
cvttss2si %xmm0,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x40(%rbp)
test   %rax,%rax
movss  %xmm0,-0x3c(%rbp)
js     1278 <main+0x158>
movss  -0x40(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x44(%rbp),%xmm0
movss  -0x3c(%rbp),%xmm1
subss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd76(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12cb <main+0x1ab>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd6b(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd47(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
jmp    12d5 <main+0x1b5>
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
jmp    11d6 <main+0xb6>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd15(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1314 <main+0x1f4>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xcfa(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    132e <main+0x20e>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xcdb(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm1
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1181 <main+0x61>
movss  -0x2c(%rbp),%xmm0
lea    0xcbe(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x2,%eax
cmp    $0x2,%edi
jl     1144 <main+0x24>
mov    0x8(%rsi),%rdi
call   1040 <atoi@plt>
test   %eax,%eax
je     1270 <main+0x150>
imul   $0xf4240,%eax,%eax
cltq
mov    $0x1,%ecx
xorps  %xmm0,%xmm0
movss  0xeab(%rip),%xmm9
movss  0xea6(%rip),%xmm10
movsd  0xea9(%rip),%xmm11
movsd  0xea9(%rip),%xmm4
movss  0xe91(%rip),%xmm5
movss  0xe8d(%rip),%xmm6
movsd  0xe98(%rip),%xmm8
jmp    11ae <main+0x8e>
nopw   0x0(%rax,%rax,1)
addsd  %xmm8,%xmm1
cvtss2sd %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x1,%rcx
cmp    %rax,%rcx
je     1273 <main+0x153>
test   %rcx,%rcx
js     11c0 <main+0xa0>
xorps  %xmm3,%xmm3
cvtsi2ss %rcx,%xmm3
jmp    11da <main+0xba>
nopl   (%rax)
mov    %rcx,%rdx
shr    %rdx
mov    %ecx,%esi
and    $0x1,%esi
or     %rdx,%rsi
xorps  %xmm3,%xmm3
cvtsi2ss %rsi,%xmm3
addss  %xmm3,%xmm3
xorps  %xmm1,%xmm1
cvtss2sd %xmm3,%xmm1
cmp    $0x2,%rcx
jae    1230 <main+0x110>
jmp    1190 <main+0x70>
nopl   0x0(%rax)
xorps  %xmm2,%xmm2
cvtsi2ss %rdx,%xmm2
movaps %xmm3,%xmm7
mulsd  %xmm11,%xmm1
addsd  %xmm4,%xmm1
cvtsd2ss %xmm1,%xmm1
subss  %xmm2,%xmm7
movaps %xmm5,%xmm2
cmpltss %xmm7,%xmm2
andps  %xmm2,%xmm1
andnps %xmm3,%xmm2
orps   %xmm1,%xmm2
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
ucomiss %xmm6,%xmm2
movaps %xmm2,%xmm3
jbe    1190 <main+0x70>
mulss  %xmm9,%xmm3
cvttss2si %xmm3,%rsi
mov    %rsi,%rdi
sar    $0x3f,%rdi
movaps %xmm3,%xmm2
subss  %xmm10,%xmm2
cvttss2si %xmm2,%rdx
and    %rdi,%rdx
or     %rsi,%rdx
jns    11f0 <main+0xd0>
mov    %rdx,%rsi
shr    %rsi
and    $0x1,%edx
or     %rsi,%rdx
xorps  %xmm2,%xmm2
cvtsi2ss %rdx,%xmm2
addss  %xmm2,%xmm2
jmp    11f8 <main+0xd8>
xorps  %xmm0,%xmm0
lea    0xdae(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"err = %e\0A\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 float
%9 = alloca float
%10 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
%18 = mul nsw i32 1000000, %17
br label %20
19: ; preds = %2
br label %20
20: ; preds = %19, %13
%21 = phi i32 [ %18, %13 ], [ 2, %19 ]
%22 = sext i32 %21 to i64
store i64 %22, i64* %6
store float 0.000000e+00, float* %10
store i64 1, i64* %7
br label %23
23: ; preds = %72, %20
%24 = load i64, i64* %7
%25 = load i64, i64* %6
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %75
27: ; preds = %23
%28 = load i64, i64* %7
%29 = uitofp i64 %28 to float
store float %29, float* %8
br label %30
30: ; preds = %53, %27
%31 = load float, float* %8
%32 = fpext float %31 to double
%33 = fcmp ogt double %32, 1.000000e+00
br i1 %33, label %34, label %54
34: ; preds = %30
%35 = load float, float* %8
%36 = fpext float %35 to double
%37 = fdiv double %36, 2.000000e+00
%38 = fptrunc double %37 to float
store float %38, float* %9
%39 = load float, float* %9
%40 = load float, float* %9
%41 = fptoui float %40 to i64
%42 = uitofp i64 %41 to float
%43 = fsub float %39, %42
%44 = fpext float %43 to double
%45 = fcmp ogt double %44, 2.500000e-01
br i1 %45, label %46, label %51
46: ; preds = %34
%47 = load float, float* %8
%48 = fpext float %47 to double
%49 = call double @llvm.fmuladd.f64(double 3.000000e+00, double %48, double 1.000000e+00)
%50 = fptrunc double %49 to float
store float %50, float* %8
br label %53
51: ; preds = %34
%52 = load float, float* %9
store float %52, float* %8
br label %53
53: ; preds = %51, %46
br label %30
54: ; preds = %30
%55 = load float, float* %8
%56 = fpext float %55 to double
%57 = fcmp ogt double %56, 1.000000e+00
br i1 %57, label %58, label %62
58: ; preds = %54
%59 = load float, float* %8
%60 = fpext float %59 to double
%61 = fsub double 1.000000e+00, %60
br label %66
62: ; preds = %54
%63 = load float, float* %8
%64 = fpext float %63 to double
%65 = fsub double %64, 1.000000e+00
br label %66
66: ; preds = %62, %58
%67 = phi double [ %61, %58 ], [ %65, %62 ]
%68 = load float, float* %10
%69 = fpext float %68 to double
%70 = fadd double %69, %67
%71 = fptrunc double %70 to float
store float %71, float* %10
br label %72
72: ; preds = %66
%73 = load i64, i64* %7
%74 = add i64 %73, 1
store i64 %74, i64* %7
br label %23
75: ; preds = %23
%76 = load float, float* %10
%77 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), float %76)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"err = %e\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = mul nsw i32 %7, 1000000
%9 = sext i32 %8 to i64
%10 = icmp eq i32 %7, 0
br i1 %10, label %40, label %11
11: ; preds = %2, %4
%12 = phi i64 [ %9, %4 ], [ 2, %2 ]
br label %13
13: ; preds = %11, %32
%14 = phi float [ %37, %32 ], [ 0.000000e+00, %11 ]
%15 = phi i64 [ %38, %32 ], [ 1, %11 ]
%16 = uitofp i64 %15 to float
%17 = fpext float %16 to double
%18 = icmp ugt i64 %15, 1
br i1 %18, label %19, label %32
19: ; preds = %13, %19
%20 = phi double [ %30, %19 ], [ %17, %13 ]
%21 = phi float [ %29, %19 ], [ %16, %13 ]
%22 = fmul float %21, 5.000000e-01
%23 = fptoui float %22 to i64
%24 = uitofp i64 %23 to float
%25 = fsub float %22, %24
%26 = fcmp ogt float %25, 2.500000e-01
%27 = tail call double @llvm.fmuladd.f64(double %20, double 3.000000e+00, double 1.000000e+00)
%28 = fptrunc double %27 to float
%29 = select i1 %26, float %28, float %22
%30 = fpext float %29 to double
%31 = fcmp ogt float %29, 1.000000e+00
br i1 %31, label %19, label %32
32: ; preds = %19, %13
%33 = phi double [ %17, %13 ], [ %30, %19 ]
%34 = fadd double %33, -1.000000e+00
%35 = fpext float %14 to double
%36 = fadd double %34, %35
%37 = fptrunc double %36 to float
%38 = add nuw i64 %15, 1
%39 = icmp eq i64 %38, %12
br i1 %39, label %40, label %13
40: ; preds = %32, %4
%41 = phi float [ 0.000000e+00, %4 ], [ %37, %32 ]
%42 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), float %41)
ret i32 0
}