#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*/ call_library(char const *, char const *, char const *, int,
                                char const **);
int /*<<< orphan*/ printf(char *);
int main(int argc, const char *argv[]) {
  if (argc <= 4) {
    printf("NX camera dynamic function call - nxcalldyn v1.0\n");
    printf("Copyright (C) 2016 Vasile Dumitrescu (ppnx.vasile@dfgh.net)\n");
    printf("License GPLv3+: GNU GPL version 3 or later "
           "<http://gnu.org/licenses/gpl.html>\n");
    printf(
        "This is free software: you are free to change and redistribute it.\n");
    printf("There is NO WARRANTY, to the extent permitted by law.\n");
    printf("\n");
    printf("Usage: nxcalldyn callType libPath funcName arg1 ...\n");
    printf("  callType is one of iii, si, vi, vv\n");
    printf("  libPath must be complete library name, including path, e.g. "
           "/usr/lib/libprefman.so\n");
  } else {
    call_library(argv[1], argv[2], argv[3], argc - 4, &argv[4]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jg     11b1 <main+0x91>
lea    0xeb9(%rip),%rdi
call   1040 <printf@plt>
lea    0xedf(%rip),%rdi
call   1040 <printf@plt>
lea    0xf10(%rip),%rdi
call   1040 <printf@plt>
lea    0xf53(%rip),%rdi
call   1040 <printf@plt>
lea    0xf8b(%rip),%rdi
call   1040 <printf@plt>
lea    0xeea(%rip),%rdi
call   1040 <printf@plt>
lea    0xfaa(%rip),%rdi
call   1040 <printf@plt>
lea    0xfd3(%rip),%rdi
call   1040 <printf@plt>
lea    0xfed(%rip),%rdi
call   1040 <printf@plt>
jmp    11dc <main+0xbc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
mov    -0x8(%rbp),%ecx
sub    $0x4,%ecx
mov    -0x10(%rbp),%r8
add    $0x20,%r8
call   1030 <call_library@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x4,%edi
jg     11a2 <main+0x72>
lea    0xec3(%rip),%rdi
call   1040 <puts@plt>
lea    0xee8(%rip),%rdi
call   1040 <puts@plt>
lea    0xf18(%rip),%rdi
call   1040 <puts@plt>
lea    0xf5a(%rip),%rdi
call   1040 <puts@plt>
lea    0xf91(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xfb1(%rip),%rdi
call   1040 <puts@plt>
lea    0xfd9(%rip),%rdi
call   1040 <puts@plt>
lea    0xff2(%rip),%rdi
call   1040 <puts@plt>
jmp    11bf <main+0x8f>
mov    %rsi,%r8
mov    %edi,%ecx
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
mov    0x18(%r8),%rdx
add    $0xfffffffc,%ecx
add    $0x20,%r8
call   1050 <call_library@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [50 x i8] c"NX camera dynamic function call - nxcalldyn v1.0\0A\00"
@.str.1 = [61 x i8] c"Copyright (C) 2016 Vasile Dumitrescu (ppnx.vasile@dfgh.net)\0A\00"
@.str.2 = [79 x i8] c"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\0A\00"
@.str.3 = [68 x i8] c"This is free software: you are free to change and redistribute it.\0A\00"
@.str.4 = [55 x i8] c"There is NO WARRANTY, to the extent permitted by law.\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [53 x i8] c"Usage: nxcalldyn callType libPath funcName arg1 ...\0A\00"
@.str.7 = [38 x i8] c" callType is one of iii, si, vi, vv\0A\00"
@.str.8 = [86 x i8] c" libPath must be complete library name, including path, e.g. /usr/lib/libprefman.so\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp sle i32 %6, 4
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.8, i64 0, i64 0))
br label %33
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 3
%27 = load i8*, i8** %26
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 4
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 4
%32 = call i32 @call_library(i8* %21, i8* %24, i8* %27, i32 %29, i8** %31)
br label %33
33: ; preds = %18, %8
ret i32 0
}

LLVM IR (-O2):
@str = [49 x i8] c"NX camera dynamic function call - nxcalldyn v1.0\00"
@str.9 = [60 x i8] c"Copyright (C) 2016 Vasile Dumitrescu (ppnx.vasile@dfgh.net)\00"
@str.10 = [78 x i8] c"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\00"
@str.11 = [67 x i8] c"This is free software: you are free to change and redistribute it.\00"
@str.12 = [54 x i8] c"There is NO WARRANTY, to the extent permitted by law.\00"
@str.13 = [52 x i8] c"Usage: nxcalldyn callType libPath funcName arg1 ...\00"
@str.14 = [37 x i8] c" callType is one of iii, si, vi, vv\00"
@str.15 = [85 x i8] c" libPath must be complete library name, including path, e.g. /usr/lib/libprefman.so\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 5
br i1 %3, label %4, label %14
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.9, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str.10, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.11, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.12, i64 0, i64 0))
%10 = tail call i32 @putchar(i32 10)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.13, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.14, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @str.15, i64 0, i64 0))
br label %24
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = add nsw i32 %0, -4
%22 = getelementptr inbounds i8*, i8** %1, i64 4
%23 = tail call i32 @call_library(i8* %16, i8* %18, i8* %20, i32 %21, i8** %22)
br label %24
24: ; preds = %14, %4
ret i32 0
}