#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 *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int strlen(char *);
int checkindexfiles(char *indexdir, char *indexname) {
  int filenamesize = 0;
  if (indexdir != NULL && indexname != NULL)
    filenamesize = strlen(indexdir) + strlen(indexname) + 8;
  else
    return 1;
  char indexfilename[filenamesize];
  int i = 0;
  sprintf(indexfilename, "/%s/%s.sph", indexdir, indexname);
  FILE *f;
  f = fopen(indexfilename, "r");
  if (!f)
    return 1;
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<checkindexfiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1194 <checkindexfiles+0x54>
cmpq   $0x0,-0x18(%rbp)
je     1194 <checkindexfiles+0x54>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
add    %ecx,%eax
add    $0x8,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a0 <checkindexfiles+0x60>
movl   $0x1,-0x4(%rbp)
jmp    1231 <checkindexfiles+0xf1>
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe24(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x50(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1213 <checkindexfiles+0xd3>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    122a <checkindexfiles+0xea>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkindexfiles>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%eax
test   %rdi,%rdi
je     11ca <checkindexfiles+0x8a>
mov    %rsi,%r14
test   %rsi,%rsi
je     11ca <checkindexfiles+0x8a>
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rsp,%r13
add    %r15d,%eax
add    $0x8,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r14,%rcx
call   1060 <sprintf@plt>
lea    0xe62(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11c2 <checkindexfiles+0x82>
mov    %rax,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11c7 <checkindexfiles+0x87>
mov    $0x1,%eax
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/%s/%s.sph\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @checkindexfiles(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %24
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %19, %21
%23 = add nsw i32 %22, 8
store i32 %23, i32* %6
br label %25
24: ; preds = %14, %2
store i32 1, i32* %3
br label %42
25: ; preds = %17
%26 = load i32, i32* %6
%27 = zext i32 %26 to i64
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %7
%29 = alloca i8, i64 %27
store i64 %27, i64* %8
store i32 0, i32* %9
%30 = load i8*, i8** %4
%31 = load i8*, i8** %5
%32 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %30, i8* %31)
%33 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %33, i32** %10
%34 = load i32*, i32** %10
%35 = icmp ne i32* %34, null
br i1 %35, label %37, label %36
36: ; preds = %25
store i32 1, i32* %3
store i32 1, i32* %11
br label %40
37: ; preds = %25
%38 = load i32*, i32** %10
%39 = call i32 @fclose(i32* %38)
store i32 0, i32* %3
store i32 1, i32* %11
br label %40
40: ; preds = %37, %36
%41 = load i8*, i8** %7
br label %42
42: ; preds = %40, %24
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [11 x i8] c"/%s/%s.sph\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @checkindexfiles(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %21
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = tail call i32 @strlen(i8* %1)
%9 = add i32 %7, 8
%10 = add i32 %9, %8
%11 = zext i32 %10 to i64
%12 = tail call i8* @llvm.stacksave()
%13 = alloca i8, i64 %11
%14 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%15 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %19, label %17
17: ; preds = %6
%18 = tail call i32 @fclose(i32* %15)
br label %19
19: ; preds = %6, %17
%20 = phi i32 [ 0, %17 ], [ 1, %6 ]
tail call void @llvm.stackrestore(i8* %12)
br label %21
21: ; preds = %2, %19
%22 = phi i32 [ %20, %19 ], [ 1, %2 ]
ret i32 %22
}