#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 */
typedef int /*<<< orphan*/ ffi_type;
typedef int /*<<< orphan*/ ffi_cif;

/* Variables and functions */
int /*<<< orphan*/ FFI_DEFAULT_ABI;
scalar_t__ FFI_OK;
int /*<<< orphan*/ ffi_call(int /*<<< orphan*/ *, void *, long *, void **);
scalar_t__ ffi_prep_cif(int /*<<< orphan*/ *, int /*<<< orphan*/, int,
                        int /*<<< orphan*/ *, int /*<<< orphan*/ **);
int /*<<< orphan*/ ffi_type_pointer;
void *fprintf;
int /*<<< orphan*/ printf(char *);
int main() {
  printf("before it all\n");
  ffi_cif cif;
  ffi_type *args[4];
  void *values[4];
  char *s1;
  char *s2;
  char *s3;
  char *s4;
  long rc;
  args[0] = &ffi_type_pointer;
  args[1] = &ffi_type_pointer;
  args[2] = &ffi_type_pointer;
  args[3] = &ffi_type_pointer;
  values[0] = &s1;
  values[1] = &s2;
  values[2] = &s3;
  values[3] = &s4;
  void *sym = fprintf;
  printf("before prep\n");
  if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, &ffi_type_pointer, args) ==
      FFI_OK) {
    s1 = "testing %s %s %s\n";
    s2 = "BLA";
    s3 = "BLI";
    s4 = "BLO";
    printf("before call\n");
    ffi_call(&cif, sym, &rc, values);
    printf("after call\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e83(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e78(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e6d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e62(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x58(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x68(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x80(%rbp)
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%r8
lea    -0x8(%rbp),%rdi
mov    $0x4,%edx
mov    0x2e07(%rip),%rcx
call   1030 <ffi_prep_cif@plt>
mov    0x2e0b(%rip),%rcx
cmp    (%rcx),%rax
jne    123f <main+0x10f>
lea    0xe2f(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xe36(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xe2f(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    0xe28(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    0xe21(%rip),%rdi
call   1040 <printf@plt>
mov    -0x80(%rbp),%rsi
lea    -0x50(%rbp),%rcx
lea    -0x8(%rbp),%rdi
lea    -0x78(%rbp),%rdx
call   1050 <ffi_call@plt>
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x78,%rsp
lea    0xee0(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e8e(%rip),%rbx
mov    %rbx,0x50(%rsp)
mov    %rbx,0x58(%rsp)
mov    %rbx,0x60(%rsp)
mov    %rbx,0x68(%rsp)
lea    0x28(%rsp),%rax
mov    %rax,0x30(%rsp)
lea    0x20(%rsp),%rax
mov    %rax,0x38(%rsp)
lea    0x18(%rsp),%rax
mov    %rax,0x40(%rsp)
lea    0x10(%rsp),%rax
mov    %rax,0x48(%rsp)
mov    0x2e43(%rip),%rax
mov    (%rax),%r14
lea    0xe95(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdi
lea    0x50(%rsp),%r8
mov    $0x4,%edx
mov    %rbx,%rcx
call   1030 <ffi_prep_cif@plt>
mov    0x2e25(%rip),%rcx
cmp    (%rcx),%rax
jne    1227 <main+0xf7>
lea    0xe31(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xe37(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xe2f(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe27(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe39(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%rdi
lea    0x70(%rsp),%rdx
lea    0x30(%rsp),%rcx
mov    %r14,%rsi
call   1050 <ffi_call@plt>
lea    0xe22(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [15 x i8] c"before it all\0A\00"
@ffi_type_pointer = global i32 0
@fprintf = global i8* null
@.str.1 = [13 x i8] c"before prep\0A\00"
@FFI_DEFAULT_ABI = global i32 0
@FFI_OK = global i64 0
@.str.2 = [18 x i8] c"testing %s %s %s\0A\00"
@.str.3 = [4 x i8] c"BLA\00"
@.str.4 = [4 x i8] c"BLI\00"
@.str.5 = [4 x i8] c"BLO\00"
@.str.6 = [13 x i8] c"before call\0A\00"
@.str.7 = [12 x i8] c"after call\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x i32*]
%4 = alloca [4 x i8*]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
store i32 0, i32* %1
%11 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [4 x i32*], [4 x i32*]* %3, i64 0, i64 0
store i32* @ffi_type_pointer, i32** %12
%13 = getelementptr inbounds [4 x i32*], [4 x i32*]* %3, i64 0, i64 1
store i32* @ffi_type_pointer, i32** %13
%14 = getelementptr inbounds [4 x i32*], [4 x i32*]* %3, i64 0, i64 2
store i32* @ffi_type_pointer, i32** %14
%15 = getelementptr inbounds [4 x i32*], [4 x i32*]* %3, i64 0, i64 3
store i32* @ffi_type_pointer, i32** %15
%16 = bitcast i8** %5 to i8*
%17 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 0
store i8* %16, i8** %17
%18 = bitcast i8** %6 to i8*
%19 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 1
store i8* %18, i8** %19
%20 = bitcast i8** %7 to i8*
%21 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 2
store i8* %20, i8** %21
%22 = bitcast i8** %8 to i8*
%23 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 3
store i8* %22, i8** %23
%24 = load i8*, i8** @fprintf
store i8* %24, i8** %10
%25 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @FFI_DEFAULT_ABI
%27 = getelementptr inbounds [4 x i32*], [4 x i32*]* %3, i64 0, i64 0
%28 = call i64 @ffi_prep_cif(i32* %2, i32 %26, i32 4, i32* @ffi_type_pointer, i32** %27)
%29 = load i64, i64* @FFI_OK
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %37
31: ; preds = %0
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %8
%32 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%33 = load i8*, i8** %10
%34 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 0
%35 = call i32 @ffi_call(i32* %2, i8* %33, i64* %9, i8** %34)
%36 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %37
37: ; preds = %31, %0
ret i32 0
}

LLVM IR (-O2):
@ffi_type_pointer = global i32 0
@fprintf = global i8* null
@FFI_DEFAULT_ABI = global i32 0
@FFI_OK = global i64 0
@.str.2 = [18 x i8] c"testing %s %s %s\0A\00"
@.str.3 = [4 x i8] c"BLA\00"
@.str.4 = [4 x i8] c"BLI\00"
@.str.5 = [4 x i8] c"BLO\00"
@str = [14 x i8] c"before it all\00"
@str.8 = [12 x i8] c"before prep\00"
@str.9 = [12 x i8] c"before call\00"
@str.10 = [11 x i8] c"after call\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i32*]
%3 = alloca [4 x i8*]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%10 = bitcast i32* %1 to i8*
%11 = bitcast [4 x i32*]* %2 to i8*
%12 = bitcast [4 x i8*]* %3 to i8*
%13 = bitcast i8** %4 to i8*
%14 = bitcast i8** %5 to i8*
%15 = bitcast i8** %6 to i8*
%16 = bitcast i8** %7 to i8*
%17 = bitcast i64* %8 to i8*
%18 = getelementptr inbounds [4 x i32*], [4 x i32*]* %2, i64 0, i64 0
store i32* @ffi_type_pointer, i32** %18
%19 = getelementptr inbounds [4 x i32*], [4 x i32*]* %2, i64 0, i64 1
store i32* @ffi_type_pointer, i32** %19
%20 = getelementptr inbounds [4 x i32*], [4 x i32*]* %2, i64 0, i64 2
store i32* @ffi_type_pointer, i32** %20
%21 = getelementptr inbounds [4 x i32*], [4 x i32*]* %2, i64 0, i64 3
store i32* @ffi_type_pointer, i32** %21
%22 = bitcast [4 x i8*]* %3 to i8***
store i8** %4, i8*** %22
%23 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 1
%24 = bitcast i8** %23 to i8***
store i8** %5, i8*** %24
%25 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 2
%26 = bitcast i8** %25 to i8***
store i8** %6, i8*** %26
%27 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 3
%28 = bitcast i8** %27 to i8***
store i8** %7, i8*** %28
%29 = load i8*, i8** @fprintf
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
%31 = load i32, i32* @FFI_DEFAULT_ABI
%32 = call i64 @ffi_prep_cif(i32* %1, i32 %31, i32 4, i32* @ffi_type_pointer, i32** %18)
%33 = load i64, i64* @FFI_OK
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %40
35: ; preds = %0
%36 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %7
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.9, i64 0, i64 0))
%38 = call i32 @ffi_call(i32* %1, i8* %29, i64* %8, i8** %36)
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.10, i64 0, i64 0))
br label %40
40: ; preds = %35, %0
ret i32 0
}