#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__ leftToRight(int);
int /*<<< orphan*/ printf(char *, int, ...);
scalar_t__ rightToLeft(int);
void problem37() {
  int count = 0, i = 0, sum = 0;
  while (count != 11) {
    i++;
    if (rightToLeft(i) && leftToRight(i)) {
      sum += i;
      printf("Value == %d\tCurrent sum = %d\n", i, sum);
      count++;
    }
  }
  printf("Total sum == %d\n\n\n", sum);
}


x86 assembly (clang, -O0):
<problem37>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xb,-0x4(%rbp)
je     11af <problem37+0x7f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <rightToLeft@plt>
cmp    $0x0,%rax
je     11aa <problem37+0x7a>
mov    -0x8(%rbp),%edi
call   1030 <leftToRight@plt>
cmp    $0x0,%rax
je     11aa <problem37+0x7a>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    114d <problem37+0x1d>
mov    -0xc(%rbp),%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<problem37>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%ebp
lea    0xebd(%rip),%r14
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    1158 <problem37+0x28>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0xb,%ebx
je     1187 <problem37+0x57>
mov    %ebp,%edi
call   1050 <rightToLeft@plt>
test   %rax,%rax
je     1150 <problem37+0x20>
mov    %ebp,%edi
call   1030 <leftToRight@plt>
test   %rax,%rax
je     1150 <problem37+0x20>
add    %ebp,%r15d
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
jmp    1150 <problem37+0x20>
lea    0xe90(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Value == %d\09Current sum = %d\0A\00"
@.str.1 = [19 x i8] c"Total sum == %d\0A\0A\0A\00"
define void @problem37() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %26, %0
%5 = load i32, i32* %1
%6 = icmp ne i32 %5, 11
br i1 %6, label %7, label %27
7: ; preds = %4
%8 = load i32, i32* %2
%9 = add nsw i32 %8, 1
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = call i64 @rightToLeft(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %7
%14 = load i32, i32* %2
%15 = call i64 @leftToRight(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = add nsw i32 %19, %18
store i32 %20, i32* %3
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22)
%24 = load i32, i32* %1
%25 = add nsw i32 %24, 1
store i32 %25, i32* %1
br label %26
26: ; preds = %17, %13, %7
br label %4
27: ; preds = %4
%28 = load i32, i32* %3
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %28)
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"Value == %d\09Current sum = %d\0A\00"
@.str.1 = [19 x i8] c"Total sum == %d\0A\0A\0A\00"
define void @problem37() {
br label %1
1: ; preds = %0, %15
%2 = phi i32 [ 0, %0 ], [ %17, %15 ]
%3 = phi i32 [ 0, %0 ], [ %5, %15 ]
%4 = phi i32 [ 0, %0 ], [ %16, %15 ]
%5 = add nuw nsw i32 %3, 1
%6 = tail call i64 @rightToLeft(i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %1
%9 = tail call i64 @leftToRight(i32 %5)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = add nsw i32 %2, %5
%13 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %12)
%14 = add nsw i32 %4, 1
br label %15
15: ; preds = %11, %8, %1
%16 = phi i32 [ %14, %11 ], [ %4, %8 ], [ %4, %1 ]
%17 = phi i32 [ %12, %11 ], [ %2, %8 ], [ %2, %1 ]
%18 = icmp eq i32 %16, 11
br i1 %18, label %19, label %1
19: ; preds = %15
%20 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %17)
ret void
}