#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 */
long call_with_0_arg(int (*)(), int, char **);
long call_with_1_arg(int (*)(), int, char **);
long call_with_2_arg(int (*)(), int, char **);
long call_with_3_arg(int (*)(), int, char **);
long call_with_4_arg(int (*)(), int, char **);
long call_with_5_arg(int (*)(), int, char **);
long call_with_6_arg(int (*)(), int, char **);
scalar_t__ is_illegal_pointer(void *);
int /*<<< orphan*/ printf(char *, ...);
void caller(int (*func)(), int argc, char **argv) {
  long ret = 0;
  switch (argc - 3) {
  case 0:
    ret = call_with_0_arg(func, argc, argv);
    break;
  case 1:
    ret = call_with_1_arg(func, argc, argv);
    break;
  case 2:
    ret = call_with_2_arg(func, argc, argv);
    break;
  case 3:
    ret = call_with_3_arg(func, argc, argv);
    break;
  case 4:
    ret = call_with_4_arg(func, argc, argv);
    break;
  case 5:
    ret = call_with_5_arg(func, argc, argv);
    break;
  case 6:
    ret = call_with_6_arg(func, argc, argv);
    break;
  default:
    break;
  }
  if (ret && is_illegal_pointer((void *)ret)) {
    printf("call returned %ld\n", ret);
  } else {
    printf("call returned '%s'\n", (char *)ret);
  }
}


x86 assembly (clang, -O0):
<caller>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0xfffffffd,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x6,%eax
ja     1283 <caller+0xf3>
mov    -0x28(%rbp),%rax
lea    0xe35(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <call_with_0_arg@plt>
mov    %rax,-0x20(%rbp)
jmp    1288 <caller+0xf8>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   10a0 <call_with_1_arg@plt>
mov    %rax,-0x20(%rbp)
jmp    1288 <caller+0xf8>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   10b0 <call_with_2_arg@plt>
mov    %rax,-0x20(%rbp)
jmp    1288 <caller+0xf8>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1060 <call_with_3_arg@plt>
mov    %rax,-0x20(%rbp)
jmp    1288 <caller+0xf8>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1080 <call_with_4_arg@plt>
mov    %rax,-0x20(%rbp)
jmp    1288 <caller+0xf8>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1090 <call_with_5_arg@plt>
mov    %rax,-0x20(%rbp)
jmp    1288 <caller+0xf8>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <call_with_6_arg@plt>
mov    %rax,-0x20(%rbp)
jmp    1288 <caller+0xf8>
jmp    1288 <caller+0xf8>
cmpq   $0x0,-0x20(%rbp)
je     12bd <caller+0x12d>
mov    -0x20(%rbp),%rdi
call   1050 <is_illegal_pointer@plt>
cmp    $0x0,%rax
je     12bd <caller+0x12d>
mov    -0x20(%rbp),%rsi
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    12cf <caller+0x13f>
mov    -0x20(%rbp),%rsi
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<caller>:
push   %rbx
add    $0xfffffffd,%esi
cmp    $0x6,%esi
ja     121d <caller+0x8d>
lea    0xe5c(%rip),%rax
movslq (%rax,%rsi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    $0x3,%esi
call   1040 <call_with_0_arg@plt>
jmp    11ff <caller+0x6f>
mov    $0x4,%esi
call   10a0 <call_with_1_arg@plt>
jmp    11ff <caller+0x6f>
mov    $0x5,%esi
call   10b0 <call_with_2_arg@plt>
jmp    11ff <caller+0x6f>
mov    $0x6,%esi
call   1060 <call_with_3_arg@plt>
jmp    11ff <caller+0x6f>
mov    $0x7,%esi
call   1080 <call_with_4_arg@plt>
jmp    11ff <caller+0x6f>
mov    $0x8,%esi
call   1090 <call_with_5_arg@plt>
jmp    11ff <caller+0x6f>
mov    $0x9,%esi
call   1030 <call_with_6_arg@plt>
mov    %rax,%rbx
test   %rax,%rax
je     121d <caller+0x8d>
mov    %rbx,%rdi
call   1050 <is_illegal_pointer@plt>
test   %rax,%rax
je     121f <caller+0x8f>
lea    0xe01(%rip),%rdi
jmp    1226 <caller+0x96>
xor    %ebx,%ebx
lea    0xe09(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
pop    %rbx
jmp    1070 <printf@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"call returned %ld\0A\00"
@.str.1 = [20 x i8] c"call returned '%s'\0A\00"
define void @caller(i32 (...)* %0, i32 %1, i8** %2) {
%4 = alloca i32 (...)*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i64
store i32 (...)* %0, i32 (...)** %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
store i64 0, i64* %7
%8 = load i32, i32* %5
%9 = sub nsw i32 %8, 3
switch i32 %9, label %45 [
i32 0, label %10
i32 1, label %15
i32 2, label %20
i32 3, label %25
i32 4, label %30
i32 5, label %35
i32 6, label %40
]
10: ; preds = %3
%11 = load i32 (...)*, i32 (...)** %4
%12 = load i32, i32* %5
%13 = load i8**, i8*** %6
%14 = call i64 @call_with_0_arg(i32 (...)* %11, i32 %12, i8** %13)
store i64 %14, i64* %7
br label %46
15: ; preds = %3
%16 = load i32 (...)*, i32 (...)** %4
%17 = load i32, i32* %5
%18 = load i8**, i8*** %6
%19 = call i64 @call_with_1_arg(i32 (...)* %16, i32 %17, i8** %18)
store i64 %19, i64* %7
br label %46
20: ; preds = %3
%21 = load i32 (...)*, i32 (...)** %4
%22 = load i32, i32* %5
%23 = load i8**, i8*** %6
%24 = call i64 @call_with_2_arg(i32 (...)* %21, i32 %22, i8** %23)
store i64 %24, i64* %7
br label %46
25: ; preds = %3
%26 = load i32 (...)*, i32 (...)** %4
%27 = load i32, i32* %5
%28 = load i8**, i8*** %6
%29 = call i64 @call_with_3_arg(i32 (...)* %26, i32 %27, i8** %28)
store i64 %29, i64* %7
br label %46
30: ; preds = %3
%31 = load i32 (...)*, i32 (...)** %4
%32 = load i32, i32* %5
%33 = load i8**, i8*** %6
%34 = call i64 @call_with_4_arg(i32 (...)* %31, i32 %32, i8** %33)
store i64 %34, i64* %7
br label %46
35: ; preds = %3
%36 = load i32 (...)*, i32 (...)** %4
%37 = load i32, i32* %5
%38 = load i8**, i8*** %6
%39 = call i64 @call_with_5_arg(i32 (...)* %36, i32 %37, i8** %38)
store i64 %39, i64* %7
br label %46
40: ; preds = %3
%41 = load i32 (...)*, i32 (...)** %4
%42 = load i32, i32* %5
%43 = load i8**, i8*** %6
%44 = call i64 @call_with_6_arg(i32 (...)* %41, i32 %42, i8** %43)
store i64 %44, i64* %7
br label %46
45: ; preds = %3
br label %46
46: ; preds = %45, %40, %35, %30, %25, %20, %15, %10
%47 = load i64, i64* %7
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %57
49: ; preds = %46
%50 = load i64, i64* %7
%51 = inttoptr i64 %50 to i8*
%52 = call i64 @is_illegal_pointer(i8* %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = load i64, i64* %7
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %55)
br label %61
57: ; preds = %49, %46
%58 = load i64, i64* %7
%59 = inttoptr i64 %58 to i8*
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %59)
br label %61
61: ; preds = %57, %54
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"call returned %ld\0A\00"
@.str.1 = [20 x i8] c"call returned '%s'\0A\00"
define void @caller(i32 (...)* %0, i32 %1, i8** %2) {
switch i32 %1, label %27 [
i32 3, label %4
i32 4, label %6
i32 5, label %8
i32 6, label %10
i32 7, label %12
i32 8, label %14
i32 9, label %16
]
4: ; preds = %3
%5 = tail call i64 @call_with_0_arg(i32 (...)* %0, i32 3, i8** %2)
br label %18
6: ; preds = %3
%7 = tail call i64 @call_with_1_arg(i32 (...)* %0, i32 4, i8** %2)
br label %18
8: ; preds = %3
%9 = tail call i64 @call_with_2_arg(i32 (...)* %0, i32 5, i8** %2)
br label %18
10: ; preds = %3
%11 = tail call i64 @call_with_3_arg(i32 (...)* %0, i32 6, i8** %2)
br label %18
12: ; preds = %3
%13 = tail call i64 @call_with_4_arg(i32 (...)* %0, i32 7, i8** %2)
br label %18
14: ; preds = %3
%15 = tail call i64 @call_with_5_arg(i32 (...)* %0, i32 8, i8** %2)
br label %18
16: ; preds = %3
%17 = tail call i64 @call_with_6_arg(i32 (...)* %0, i32 9, i8** %2)
br label %18
18: ; preds = %16, %14, %12, %10, %8, %6, %4
%19 = phi i64 [ %17, %16 ], [ %15, %14 ], [ %13, %12 ], [ %11, %10 ], [ %9, %8 ], [ %7, %6 ], [ %5, %4 ]
%20 = icmp eq i64 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %18
%22 = inttoptr i64 %19 to i8*
%23 = tail call i64 @is_illegal_pointer(i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %19)
br label %31
27: ; preds = %3, %21, %18
%28 = phi i64 [ %19, %21 ], [ 0, %18 ], [ 0, %3 ]
%29 = inttoptr i64 %28 to i8*
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %27, %25
ret void
}