#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 /*<<< orphan*/ lps(int, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, m, l, i;
  printf("Enter value of n : ");
  scanf("%d", &n);
  lps(n, 1, 1, n);
  for (i = 1, m = 0; i < n; m++, i *= 2)
    ;
  i /= 2;
  m--;
  l = n - i;
  printf("\nChecking the Formula\nm = %d", m);
  printf("\nl = %d\nAnswer = 2*(l+1) = %d", l, (2 * l + 1));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef8(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%ecx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <lps@plt>
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a5 <main+0x75>
jmp    118e <main+0x5e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117d <main+0x4d>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%edx
shl    $0x1,%edx
add    $0x1,%edx
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xefd(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%ecx
mov    $0x1,%ebp
mov    %ecx,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1040 <lps@plt>
mov    0xc(%rsp),%r14d
mov    $0xffffffff,%esi
cmp    $0x2,%r14d
jl     11a3 <main+0x73>
mov    $0xffffffff,%esi
nopl   0x0(%rax,%rax,1)
mov    %ebp,%ebx
lea    (%rbx,%rbx,1),%ebp
add    $0x1,%esi
cmp    %r14d,%ebp
jl     1190 <main+0x60>
and    $0x7fffffff,%ebx
sub    %ebx,%r14d
lea    0xe67(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    (%r14,%r14,1),%edx
add    $0x1,%edx
lea    0xe6f(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter value of n : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"\0AChecking the Formula\0Am = %d\00"
@.str.3 = [30 x i8] c"\0Al = %d\0AAnswer = 2*(l+1) = %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = load i32, i32* %2
%10 = call i32 @lps(i32 %8, i32 1, i32 1, i32 %9)
store i32 1, i32* %5
store i32 0, i32* %3
br label %11
11: ; preds = %16, %0
%12 = load i32, i32* %5
%13 = load i32, i32* %2
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %21
15: ; preds = %11
br label %16
16: ; preds = %15
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
%19 = load i32, i32* %5
%20 = mul nsw i32 %19, 2
store i32 %20, i32* %5
br label %11
21: ; preds = %11
%22 = load i32, i32* %5
%23 = sdiv i32 %22, 2
store i32 %23, i32* %5
%24 = load i32, i32* %3
%25 = add nsw i32 %24, -1
store i32 %25, i32* %3
%26 = load i32, i32* %2
%27 = load i32, i32* %5
%28 = sub nsw i32 %26, %27
store i32 %28, i32* %4
%29 = load i32, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %4
%32 = load i32, i32* %4
%33 = mul nsw i32 2, %32
%34 = add nsw i32 %33, 1
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %34)
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [20 x i8] c"Enter value of n : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"\0AChecking the Formula\0Am = %d\00"
@.str.3 = [30 x i8] c"\0Al = %d\0AAnswer = 2*(l+1) = %d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = call i32 @lps(i32 %5, i32 1, i32 1, i32 %5)
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %17
9: ; preds = %0, %9
%10 = phi i32 [ %13, %9 ], [ 1, %0 ]
%11 = phi i32 [ %12, %9 ], [ 0, %0 ]
%12 = add nuw nsw i32 %11, 1
%13 = shl nsw i32 %10, 1
%14 = icmp slt i32 %13, %7
br i1 %14, label %9, label %15
15: ; preds = %9
%16 = and i32 %10, 2147483647
br label %17
17: ; preds = %15, %0
%18 = phi i32 [ -1, %0 ], [ %11, %15 ]
%19 = phi i32 [ 0, %0 ], [ %16, %15 ]
%20 = sub nsw i32 %7, %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%22 = shl nsw i32 %20, 1
%23 = or i32 %22, 1
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 %23)
ret i32 0
}