#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int asprintf(char **, char *, char const *, char const *);
int stat(char *, struct stat *);
int validate_repo(const char *repo_root, const char *subdir) {
  char *abs_path;
  struct stat st;
  int ret;
  if (asprintf(&abs_path, "%s.hg/%s", repo_root, subdir) == -1) {
    ret = -1;
    goto bail;
  }
  if (stat(abs_path, &st) == -1) {
    ret = 0;
  } else {
    ret = 1;
  }
bail:
  return ret;
}


x86 assembly (clang, -O0):
<validate_repo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
lea    0xebd(%rip),%rsi
call   1040 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    115d <validate_repo+0x3d>
movl   $0xffffffff,-0x24(%rbp)
jmp    118b <validate_repo+0x6b>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0xffffffff,%eax
jne    117f <validate_repo+0x5f>
movl   $0x0,-0x24(%rbp)
jmp    1186 <validate_repo+0x66>
movl   $0x1,-0x24(%rbp)
jmp    118b <validate_repo+0x6b>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_repo>:
sub    $0x18,%rsp
mov    %rsi,%rcx
mov    %rdi,%rdx
lea    0xecf(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1040 <asprintf@plt>
cmp    $0xffffffff,%eax
je     115e <validate_repo+0x3e>
mov    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
setne  %al
add    $0x18,%rsp
ret
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [9 x i8] c"%s.hg/%s\00"
define i32 @validate_repo(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = bitcast i8** %3 to i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i32 @stat(i8* %10, %struct.stat* %4)
%12 = icmp ne i32 %11, -1
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %9, %2
%15 = phi i32 [ -1, %2 ], [ %13, %9 ]
ret i32 %15
}