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

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, ...);
int test_and_create(char *);
int check_dir_i(const char *dir, int i) {
  char buf[1024];
  if (dir == NULL)
    dir = ".";
  if (i >= 0)
    snprintf(buf, sizeof(buf), "%s/%d", dir, i);
  else
    snprintf(buf, sizeof(buf), "%s", dir);
  if (test_and_create(buf) == -1)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<check_dir_i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1148 <check_dir_i+0x28>
lea    0xebc(%rip),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1179 <check_dir_i+0x59>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    $0x400,%esi
lea    0xe95(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    1197 <check_dir_i+0x77>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x400,%esi
lea    0xe78(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x420(%rbp),%rdi
call   1030 <test_and_create@plt>
cmp    $0xffffffff,%eax
jne    11b8 <check_dir_i+0x98>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <check_dir_i+0x9f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_dir_i>:
sub    $0x408,%rsp
test   %rdi,%rdi
lea    0xecf(%rip),%rcx
cmovne %rdi,%rcx
test   %esi,%esi
js     1154 <check_dir_i+0x34>
mov    %esi,%r8d
lea    0xebf(%rip),%rdx
mov    %rsp,%rdi
mov    $0x400,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    116a <check_dir_i+0x4a>
lea    0xead(%rip),%rdx
mov    %rsp,%rdi
mov    $0x400,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rsp,%rdi
call   1030 <test_and_create@plt>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
sete   %cl
neg    %ecx
mov    %ecx,%eax
add    $0x408,%rsp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [6 x i8] c"%s/%d\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @check_dir_i(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [1024 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4
br label %10
10: ; preds = %9, %2
%11 = load i32, i32* %5
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%15 = load i8*, i8** %4
%16 = load i32, i32* %5
%17 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %14, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32 %16)
br label %22
18: ; preds = %10
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%20 = load i8*, i8** %4
%21 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %19, i32 1024, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %18, %13
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%24 = call i32 @test_and_create(i8* %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 -1, i32* %3
br label %28
27: ; preds = %22
store i32 0, i32* %3
br label %28
28: ; preds = %27, %26
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [6 x i8] c"%s/%d\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @check_dir_i(i8* %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %0, null
%6 = select i1 %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %0
%7 = icmp sgt i32 %1, -1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %4, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %6, i32 %1)
br label %12
10: ; preds = %2
%11 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %4, i32 1024, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %12
12: ; preds = %10, %8
%13 = call i32 @test_and_create(i8* %4)
%14 = icmp eq i32 %13, -1
%15 = sext i1 %14 to i32
ret i32 %15
}