#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*/ init_callbacks(int (*)(int, int));
int /*<<< orphan*/ printf(char *, ...);
int stub1(int, int);
int stub2(int, int);
int stub3(int, int);
int main(int argc, char *argv[]) {
  int retval = 0;
  int (*cb[3])(int, int);
  init_callbacks(&cb);
  if (argc == 1) {
  } else if (argc == 2) {
    retval = cb[0](argc + 2, argc);
    printf("add_one is called\n");
  } else if (argc == 3) {
    retval = cb[1](argc + 3, argc);
    printf("add_two is called\n");
  } else if (argc == 4) {
    retval = cb[2](argc + 4, argc);
    printf("add_three is called\n");
  } else {
  }
  printf("Final retval=%d\n", retval);
  return retval;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <init_callbacks@plt>
cmpl   $0x1,-0x8(%rbp)
jne    1155 <main+0x35>
jmp    11f6 <main+0xd6>
cmpl   $0x2,-0x8(%rbp)
jne    1184 <main+0x64>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%edi
add    $0x2,%edi
mov    -0x8(%rbp),%esi
call   *%rax
mov    %eax,-0x14(%rbp)
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f1 <main+0xd1>
cmpl   $0x3,-0x8(%rbp)
jne    11b3 <main+0x93>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%edi
add    $0x3,%edi
mov    -0x8(%rbp),%esi
call   *%rax
mov    %eax,-0x14(%rbp)
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ec <main+0xcc>
cmpl   $0x4,-0x8(%rbp)
jne    11e2 <main+0xc2>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%edi
add    $0x4,%edi
mov    -0x8(%rbp),%esi
call   *%rax
mov    %eax,-0x14(%rbp)
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e7 <main+0xc7>
jmp    11e7 <main+0xc7>
jmp    11ec <main+0xcc>
jmp    11f1 <main+0xd1>
jmp    11f6 <main+0xd6>
mov    -0x14(%rbp),%esi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
mov    %rsp,%rdi
call   1030 <init_callbacks@plt>
cmp    $0x4,%ebp
je     1169 <main+0x39>
cmp    $0x3,%ebp
je     1182 <main+0x52>
xor    %ebx,%ebx
cmp    $0x2,%ebp
jne    119e <main+0x6e>
mov    $0x4,%edi
mov    $0x2,%esi
call   *(%rsp)
mov    %eax,%ebx
lea    0xed0(%rip),%rdi
jmp    1199 <main+0x69>
mov    $0x8,%edi
mov    $0x4,%esi
call   *0x10(%rsp)
mov    %eax,%ebx
lea    0xe91(%rip),%rdi
jmp    1199 <main+0x69>
mov    $0x6,%edi
mov    $0x3,%esi
call   *0x8(%rsp)
mov    %eax,%ebx
lea    0xe8c(%rip),%rdi
call   1040 <puts@plt>
lea    0xe5b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"add_one is called\0A\00"
@.str.1 = [19 x i8] c"add_two is called\0A\00"
@.str.2 = [21 x i8] c"add_three is called\0A\00"
@.str.3 = [17 x i8] c"Final retval=%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [3 x i32 (i32, i32)*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = bitcast [3 x i32 (i32, i32)*]* %7 to i32 (i32, i32)*
%9 = call i32 @init_callbacks(i32 (i32, i32)* %8)
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %2
br label %50
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = getelementptr inbounds [3 x i32 (i32, i32)*], [3 x i32 (i32, i32)*]* %7, i64 0, i64 0
%18 = load i32 (i32, i32)*, i32 (i32, i32)** %17
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 2
%21 = load i32, i32* %4
%22 = call i32 %18(i32 %20, i32 %21)
store i32 %22, i32* %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %49
24: ; preds = %13
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 3
br i1 %26, label %27, label %35
27: ; preds = %24
%28 = getelementptr inbounds [3 x i32 (i32, i32)*], [3 x i32 (i32, i32)*]* %7, i64 0, i64 1
%29 = load i32 (i32, i32)*, i32 (i32, i32)** %28
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 3
%32 = load i32, i32* %4
%33 = call i32 %29(i32 %31, i32 %32)
store i32 %33, i32* %6
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %48
35: ; preds = %24
%36 = load i32, i32* %4
%37 = icmp eq i32 %36, 4
br i1 %37, label %38, label %46
38: ; preds = %35
%39 = getelementptr inbounds [3 x i32 (i32, i32)*], [3 x i32 (i32, i32)*]* %7, i64 0, i64 2
%40 = load i32 (i32, i32)*, i32 (i32, i32)** %39
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 4
%43 = load i32, i32* %4
%44 = call i32 %40(i32 %42, i32 %43)
store i32 %44, i32* %6
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %47
46: ; preds = %35
br label %47
47: ; preds = %46, %38
br label %48
48: ; preds = %47, %27
br label %49
49: ; preds = %48, %16
br label %50
50: ; preds = %49, %12
%51 = load i32, i32* %6
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %51)
%53 = load i32, i32* %6
ret i32 %53
}

LLVM IR (-O2):
@.str.3 = [17 x i8] c"Final retval=%d\0A\00"
@str = [20 x i8] c"add_three is called\00"
@str.4 = [18 x i8] c"add_two is called\00"
@str.5 = [18 x i8] c"add_one is called\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x i32 (i32, i32)*]
%4 = bitcast [3 x i32 (i32, i32)*]* %3 to i8*
%5 = bitcast [3 x i32 (i32, i32)*]* %3 to i32 (i32, i32)*
%6 = call i32 @init_callbacks(i32 (i32, i32)* %5)
switch i32 %0, label %23 [
i32 4, label %15
i32 2, label %7
i32 3, label %11
]
7: ; preds = %2
%8 = getelementptr inbounds [3 x i32 (i32, i32)*], [3 x i32 (i32, i32)*]* %3, i64 0, i64 0
%9 = load i32 (i32, i32)*, i32 (i32, i32)** %8
%10 = call i32 %9(i32 4, i32 2)
br label %19
11: ; preds = %2
%12 = getelementptr inbounds [3 x i32 (i32, i32)*], [3 x i32 (i32, i32)*]* %3, i64 0, i64 1
%13 = load i32 (i32, i32)*, i32 (i32, i32)** %12
%14 = call i32 %13(i32 6, i32 3)
br label %19
15: ; preds = %2
%16 = getelementptr inbounds [3 x i32 (i32, i32)*], [3 x i32 (i32, i32)*]* %3, i64 0, i64 2
%17 = load i32 (i32, i32)*, i32 (i32, i32)** %16
%18 = call i32 %17(i32 8, i32 4)
br label %19
19: ; preds = %11, %15, %7
%20 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.5, i64 0, i64 0), %7 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0), %15 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0), %11 ]
%21 = phi i32 [ %10, %7 ], [ %18, %15 ], [ %14, %11 ]
%22 = call i32 @puts(i8* dereferenceable(1) %20)
br label %23
23: ; preds = %19, %2
%24 = phi i32 [ 0, %2 ], [ %21, %19 ]
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %24)
ret i32 %24
}