#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__ log2(long long);
int /*<<< orphan*/ printf(char *, long long);
int scanf(char *, long long *);
int main() {
  long long n;
  while (scanf("%lli", &n) == 1)
    printf("%lli\n", (n - 1) + (int)log2(n - 1));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    118b <main+0x5b>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
sub    $0x1,%rdi
call   1030 <log2@plt>
mov    -0x18(%rbp),%rsi
cltq
add    %rax,%rsi
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
jmp    113f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xec1(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    118f <main+0x5f>
lea    0xeb2(%rip),%r14
lea    0xea6(%rip),%r15
mov    %rsp,%r12
nopl   (%rax)
mov    (%rsp),%rbx
lea    -0x1(%rbx),%rdi
call   1030 <log2@plt>
cltq
lea    (%rax,%rbx,1),%rsi
add    $0xffffffffffffffff,%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
je     1160 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lli\00"
@.str.1 = [6 x i8] c"%lli\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
br label %3
3: ; preds = %6, %0
%4 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %2)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %16
6: ; preds = %3
%7 = load i64, i64* %2
%8 = sub nsw i64 %7, 1
%9 = load i64, i64* %2
%10 = sub nsw i64 %9, 1
%11 = call i64 @log2(i64 %10)
%12 = trunc i64 %11 to i32
%13 = sext i32 %12 to i64
%14 = add nsw i64 %8, %13
%15 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %14)
br label %3
16: ; preds = %3
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lli\00"
@.str.1 = [6 x i8] c"%lli\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %15
5: ; preds = %0, %5
%6 = load i64, i64* %1
%7 = add nsw i64 %6, -1
%8 = call i64 @log2(i64 %7)
%9 = shl i64 %8, 32
%10 = ashr exact i64 %9, 32
%11 = add nsw i64 %10, %7
%12 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %11)
%13 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %1)
%14 = icmp eq i32 %13, 1
br i1 %14, label %5, label %15
15: ; preds = %5, %0
ret i32 0
}