#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*/ adafinal();
int /*<<< orphan*/ adainit();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ test_manypaths();
int /*<<< orphan*/ test_newton();
int /*<<< orphan*/ test_onepath();
int main(int argc, char *argv[]) {
  int choice;
  char ch;
  adainit();
  printf("\nMENU to apply algorithmic differentiation : \n");
  printf("  0. in Newton's method to correct one solution;\n");
  printf("  1. to track one solution path;\n");
  printf("  2. to track many solution paths.\n");
  printf("Type 0, 1, or 2 to select : ");
  scanf("%d", &choice);
  scanf("%c", &ch);
  if (choice == 0)
    test_newton();
  else if (choice == 1)
    test_onepath();
  else if (choice == 2)
    test_manypaths();
  else
    printf("invalid selection, please try again\n");
  adafinal();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <adainit@plt>
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb5(%rip),%rdi
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
call   1030 <printf@plt>
lea    0xee3(%rip),%rdi
call   1030 <printf@plt>
lea    0xef4(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
lea    0xee5(%rip),%rdi
lea    -0x15(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1203 <main+0x93>
mov    $0x0,%al
call   1090 <test_newton@plt>
jmp    1245 <main+0xd5>
cmpl   $0x1,-0x14(%rbp)
jne    1219 <main+0xa9>
mov    $0x0,%al
call   1050 <test_onepath@plt>
jmp    1240 <main+0xd0>
cmpl   $0x2,-0x14(%rbp)
jne    122f <main+0xbf>
mov    $0x0,%al
call   1040 <test_manypaths@plt>
jmp    123b <main+0xcb>
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
jmp    1240 <main+0xd0>
jmp    1245 <main+0xd5>
mov    $0x0,%al
call   1060 <adafinal@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1090 <adainit@plt>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
lea    0xef0(%rip),%rdi
call   1030 <puts@plt>
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
lea    0xe52(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
lea    0xe42(%rip),%rdi
lea    0x3(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x2,%eax
je     1205 <main+0x85>
cmp    $0x1,%eax
je     120e <main+0x8e>
test   %eax,%eax
jne    1217 <main+0x97>
xor    %eax,%eax
call   10a0 <test_newton@plt>
jmp    1223 <main+0xa3>
xor    %eax,%eax
call   1050 <test_manypaths@plt>
jmp    1223 <main+0xa3>
xor    %eax,%eax
call   1060 <test_onepath@plt>
jmp    1223 <main+0xa3>
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <adafinal@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [47 x i8] c"\0AMENU to apply algorithmic differentiation : \0A\00"
@.str.1 = [50 x i8] c" 0. in Newton's method to correct one solution;\0A\00"
@.str.2 = [34 x i8] c" 1. to track one solution path;\0A\00"
@.str.3 = [36 x i8] c" 2. to track many solution paths.\0A\00"
@.str.4 = [29 x i8] c"Type 0, 1, or 2 to select : \00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [3 x i8] c"%c\00"
@.str.7 = [37 x i8] c"invalid selection, please try again\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @adainit()
%9 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %6)
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %7)
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 (...) @test_newton()
br label %34
20: ; preds = %2
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 (...) @test_onepath()
br label %33
25: ; preds = %20
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 2
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 (...) @test_manypaths()
br label %32
30: ; preds = %25
%31 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
br label %32
32: ; preds = %30, %28
br label %33
33: ; preds = %32, %23
br label %34
34: ; preds = %33, %18
%35 = call i32 (...) @adafinal()
ret i32 0
}

LLVM IR (-O2):
@.str.4 = [29 x i8] c"Type 0, 1, or 2 to select : \00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [3 x i8] c"%c\00"
@str = [46 x i8] c"\0AMENU to apply algorithmic differentiation : \00"
@str.8 = [49 x i8] c" 0. in Newton's method to correct one solution;\00"
@str.9 = [33 x i8] c" 1. to track one solution path;\00"
@str.10 = [35 x i8] c" 2. to track many solution paths.\00"
@str.11 = [36 x i8] c"invalid selection, please try again\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i8
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 (...) @adainit()
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.8, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.9, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.10, i64 0, i64 0))
%11 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%14 = load i32, i32* %3
switch i32 %14, label %21 [
i32 0, label %15
i32 1, label %17
i32 2, label %19
]
15: ; preds = %2
%16 = call i32 (...) @test_newton()
br label %23
17: ; preds = %2
%18 = call i32 (...) @test_onepath()
br label %23
19: ; preds = %2
%20 = call i32 (...) @test_manypaths()
br label %23
21: ; preds = %2
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.11, i64 0, i64 0))
br label %23
23: ; preds = %17, %21, %19, %15
%24 = call i32 (...) @adafinal()
ret i32 0
}