#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 *fopen;
int main() {
  ffi_cif cif;
  ffi_type *args[2];
  void *values[2];
  char *s1;
  char *s2;
  long rc;
  args[0] = &ffi_type_pointer;
  args[1] = &ffi_type_pointer;
  values[0] = &s1;
  values[1] = &s2;
  void *sym = fopen;
  if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_pointer, args) ==
      FFI_OK) {
    s1 = "f1.txt";
    s2 = "w";
    ffi_call(&cif, sym, &rc, values);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e8f(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e84(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%r8
lea    -0x8(%rbp),%rdi
mov    $0x2,%edx
mov    0x2e50(%rip),%rcx
call   1030 <ffi_prep_cif@plt>
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%rax
jne    11c0 <main+0xa0>
lea    0xe64(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe60(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x50(%rbp),%rsi
lea    -0x30(%rbp),%rcx
lea    -0x8(%rbp),%rdi
lea    -0x48(%rbp),%rdx
call   1040 <ffi_call@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
mov    0x2ea4(%rip),%rcx
mov    %rcx,0x30(%rsp)
mov    %rcx,0x38(%rsp)
lea    0x18(%rsp),%rax
mov    %rax,0x20(%rsp)
lea    0x10(%rsp),%rax
mov    %rax,0x28(%rsp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%rbx
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdi
lea    0x30(%rsp),%r8
mov    $0x2,%edx
call   1030 <ffi_prep_cif@plt>
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
jne    11ac <main+0x8c>
lea    0xe7c(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe77(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xc(%rsp),%rdi
lea    0x48(%rsp),%rdx
lea    0x20(%rsp),%rcx
mov    %rbx,%rsi
call   1040 <ffi_call@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@ffi_type_pointer = global i32 0
@fopen = global i8* null
@FFI_DEFAULT_ABI = global i32 0
@FFI_OK = global i64 0
@.str = [7 x i8] c"f1.txt\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i32*]
%4 = alloca [2 x i8*]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
store i32 0, i32* %1
%9 = getelementptr inbounds [2 x i32*], [2 x i32*]* %3, i64 0, i64 0
store i32* @ffi_type_pointer, i32** %9
%10 = getelementptr inbounds [2 x i32*], [2 x i32*]* %3, i64 0, i64 1
store i32* @ffi_type_pointer, i32** %10
%11 = bitcast i8** %5 to i8*
%12 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
store i8* %11, i8** %12
%13 = bitcast i8** %6 to i8*
%14 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 1
store i8* %13, i8** %14
%15 = load i8*, i8** @fopen
store i8* %15, i8** %8
%16 = load i32, i32* @FFI_DEFAULT_ABI
%17 = getelementptr inbounds [2 x i32*], [2 x i32*]* %3, i64 0, i64 0
%18 = call i64 @ffi_prep_cif(i32* %2, i32 %16, i32 2, i32* @ffi_type_pointer, i32** %17)
%19 = load i64, i64* @FFI_OK
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %0
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %6
%22 = load i8*, i8** %8
%23 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
%24 = call i32 @ffi_call(i32* %2, i8* %22, i64* %7, i8** %23)
br label %25
25: ; preds = %21, %0
ret i32 0
}

LLVM IR (-O2):
@ffi_type_pointer = global i32 0
@fopen = global i8* null
@FFI_DEFAULT_ABI = global i32 0
@FFI_OK = global i64 0
@.str = [7 x i8] c"f1.txt\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32*]
%3 = alloca [2 x i8*]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = bitcast i32* %1 to i8*
%8 = bitcast [2 x i32*]* %2 to i8*
%9 = bitcast [2 x i8*]* %3 to i8*
%10 = bitcast i8** %4 to i8*
%11 = bitcast i8** %5 to i8*
%12 = bitcast i64* %6 to i8*
%13 = getelementptr inbounds [2 x i32*], [2 x i32*]* %2, i64 0, i64 0
store i32* @ffi_type_pointer, i32** %13
%14 = getelementptr inbounds [2 x i32*], [2 x i32*]* %2, i64 0, i64 1
store i32* @ffi_type_pointer, i32** %14
%15 = bitcast [2 x i8*]* %3 to i8***
store i8** %4, i8*** %15
%16 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 1
%17 = bitcast i8** %16 to i8***
store i8** %5, i8*** %17
%18 = load i8*, i8** @fopen
%19 = load i32, i32* @FFI_DEFAULT_ABI
%20 = call i64 @ffi_prep_cif(i32* %1, i32 %19, i32 2, i32* @ffi_type_pointer, i32** %13)
%21 = load i64, i64* @FFI_OK
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %0
%24 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %5
%25 = call i32 @ffi_call(i32* %1, i8* %18, i64* %6, i8** %24)
br label %26
26: ; preds = %23, %0
ret i32 0
}