#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *myprintf(char *, char const *, char const *);
int isModuleExistant(const char *modPath, const char *modName,
                     char **finalPath) {
  FILE *file;
  int retour = 1;
  *finalPath = myprintf("%s/%s.so", modPath, modName);
  if ((file = fopen(*finalPath, "rb")) == NULL)
    retour = 0;
  else {
    fclose(file);
    retour = 1;
  }
  return retour;
}


x86 assembly (clang, -O0):
<isModuleExistant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xea6(%rip),%rdi
call   1040 <myprintf@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe92(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1196 <isModuleExistant+0x66>
movl   $0x0,-0x24(%rbp)
jmp    11a6 <isModuleExistant+0x76>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isModuleExistant>:
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%rdx
mov    %rdi,%rsi
lea    0xebf(%rip),%rdi
call   1040 <myprintf@plt>
mov    %rax,(%rbx)
lea    0xeb9(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     116c <isModuleExistant+0x3c>
mov    %rax,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%s/%s.so\00"
@.str.1 = [3 x i8] c"rb\00"
define i32 @isModuleExistant(i8* %0, i8* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8** %2, i8*** %6
store i32 1, i32* %8
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i8* @myprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %10)
%12 = load i8**, i8*** %6
store i8* %11, i8** %12
%13 = load i8**, i8*** %6
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %7
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 0, i32* %8
br label %21
18: ; preds = %3
%19 = load i32*, i32** %7
%20 = call i32 @fclose(i32* %19)
store i32 1, i32* %8
br label %21
21: ; preds = %18, %17
%22 = load i32, i32* %8
ret i32 %22
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s/%s.so\00"
@.str.1 = [3 x i8] c"rb\00"
define i32 @isModuleExistant(i8* %0, i8* %1, i8** nocapture writeonly %2) {
%4 = tail call i8* @myprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
store i8* %4, i8** %2
%5 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 @fclose(i32* %5)
br label %9
9: ; preds = %3, %7
%10 = phi i32 [ 1, %7 ], [ 0, %3 ]
ret i32 %10
}