#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 pow(int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, int *);
void dropping() {
  int d, i, leaf_count, first_leaf;
  scanf("%d%d", &d, &i);
  leaf_count = pow(2, (d - 1));
  first_leaf = leaf_count;
  i %= leaf_count;
  if (!i)
    i = leaf_count;
  while (i > 1) {
    leaf_count /= 2;
    if (i % 2) {
      i -= (i / 2);
    } else {
      first_leaf += leaf_count;
      i /= 2;
    }
  }
  printf("%d\n", first_leaf);
}


x86 assembly (clang, -O0):
<dropping>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
lea    -0x4(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0x4(%rbp),%esi
sub    $0x1,%esi
mov    $0x2,%edi
call   1050 <pow@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1181 <dropping+0x51>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1186 <dropping+0x56>
cmpl   $0x1,-0x8(%rbp)
jle    11e8 <dropping+0xb8>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11cc <dropping+0x9c>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    11e3 <dropping+0xb3>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1186 <dropping+0x56>
mov    -0x10(%rbp),%esi
lea    0xe13(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dropping>:
push   %rax
lea    0xec8(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <scanf@plt>
mov    0x4(%rsp),%esi
add    $0xffffffff,%esi
mov    $0x2,%edi
call   1050 <pow@plt>
mov    %eax,%esi
mov    (%rsp),%eax
cltd
idiv   %esi
test   %edx,%edx
cmove  %esi,%edx
cmp    $0x2,%edx
jl     1198 <dropping+0x68>
mov    %esi,%edi
mov    %esi,%ecx
mov    %edx,%eax
xchg   %ax,%ax
shr    $0x1f,%ecx
add    %edi,%ecx
sar    %ecx
mov    %edx,%edi
shr    %edi
sub    %edi,%eax
test   $0x1,%dl
cmove  %edi,%eax
mov    $0x0,%edx
cmove  %ecx,%edx
add    %edx,%esi
mov    %ecx,%edi
mov    %eax,%edx
cmp    $0x1,%eax
jg     1170 <dropping+0x40>
jmp    119a <dropping+0x6a>
mov    %edx,%eax
mov    %eax,(%rsp)
lea    0xe61(%rip),%rdi
call   1030 <printf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define void @dropping() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%6 = load i32, i32* %1
%7 = sub nsw i32 %6, 1
%8 = call i32 @pow(i32 2, i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
store i32 %9, i32* %4
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = srem i32 %11, %10
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %0
%16 = load i32, i32* %3
store i32 %16, i32* %2
br label %17
17: ; preds = %15, %0
br label %18
18: ; preds = %38, %17
%19 = load i32, i32* %2
%20 = icmp sgt i32 %19, 1
br i1 %20, label %21, label %39
21: ; preds = %18
%22 = load i32, i32* %3
%23 = sdiv i32 %22, 2
store i32 %23, i32* %3
%24 = load i32, i32* %2
%25 = srem i32 %24, 2
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %21
%28 = load i32, i32* %2
%29 = sdiv i32 %28, 2
%30 = load i32, i32* %2
%31 = sub nsw i32 %30, %29
store i32 %31, i32* %2
br label %38
32: ; preds = %21
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = add nsw i32 %34, %33
store i32 %35, i32* %4
%36 = load i32, i32* %2
%37 = sdiv i32 %36, 2
store i32 %37, i32* %2
br label %38
38: ; preds = %32, %27
br label %18
39: ; preds = %18
%40 = load i32, i32* %4
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %40)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define void @dropping() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, -1
%8 = call i32 @pow(i32 2, i32 %7)
%9 = load i32, i32* %2
%10 = srem i32 %9, %8
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i32 %8, i32 %10
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %27
14: ; preds = %0, %14
%15 = phi i32 [ %25, %14 ], [ %8, %0 ]
%16 = phi i32 [ %18, %14 ], [ %8, %0 ]
%17 = phi i32 [ %23, %14 ], [ %12, %0 ]
%18 = sdiv i32 %16, 2
%19 = and i32 %17, 1
%20 = icmp eq i32 %19, 0
%21 = lshr i32 %17, 1
%22 = sub nsw i32 %17, %21
%23 = select i1 %20, i32 %21, i32 %22
%24 = select i1 %20, i32 %18, i32 0
%25 = add nsw i32 %15, %24
%26 = icmp sgt i32 %23, 1
br i1 %26, label %14, label %27
27: ; preds = %14, %0
%28 = phi i32 [ %12, %0 ], [ %23, %14 ]
%29 = phi i32 [ %8, %0 ], [ %25, %14 ]
store i32 %28, i32* %2
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %29)
ret void
}