#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 /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char *);
bool repo_exists(char *dir) {
  char git_dir[1024] = "";
  strcat(git_dir, dir);
  strcat(git_dir, ".git/");
  struct stat gdd;
  if (!stat(git_dir, &gdd) && S_ISDIR(gdd.st_mode)) {
    return true;
  } else {
    return false;
  }
}


x86 assembly (clang, -O0):
<repo_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1060 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    -0x418(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%eax
jne    11c2 <repo_exists+0x82>
mov    -0x418(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11c2 <repo_exists+0x82>
movl   $0x1,-0x4(%rbp)
jmp    11c9 <repo_exists+0x89>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<repo_exists>:
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    %rdi,%r14
lea    0x10(%rsp),%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
test   %eax,%eax
jne    11a2 <repo_exists+0x62>
mov    0x8(%rsp),%edi
call   1030 <S_ISDIR@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11a4 <repo_exists+0x64>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret

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

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