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

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ assert(int);
scalar_t__ chdir(char const *);
char *getcwd(char *, int);
char *git__pipe_read(char *);
char *git_current_commit(const char *path) {
  if (!path)
    return NULL;
  char pdir[PATH_MAX];
  if (getcwd(pdir, PATH_MAX) != pdir)
    return NULL;
  if (chdir(path) != 0)
    return NULL;
  char *commit = git__pipe_read("git rev-parse HEAD");
  assert(chdir(pdir) == 0);
  return commit;
}


x86 assembly (clang, -O0):
<git_current_commit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <git_current_commit+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1226 <git_current_commit+0xe6>
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
call   1050 <getcwd@plt>
mov    -0x38(%rbp),%rcx
cmp    %rcx,%rax
je     11bf <git_current_commit+0x7f>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    121f <git_current_commit+0xdf>
mov    -0x10(%rbp),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
je     11e6 <git_current_commit+0xa6>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    121f <git_current_commit+0xdf>
lea    0xe13(%rip),%rdi
call   1030 <git__pipe_read@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,-0x30(%rbp)
call   1040 <chdir@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<git_current_commit>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1193 <git_current_commit+0x53>
mov    %rdi,%r14
mov    %rsp,%r15
mov    0x2e94(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <getcwd@plt>
cmp    %rbx,%rax
jne    118b <git_current_commit+0x4b>
mov    %r14,%rdi
call   1040 <chdir@plt>
test   %rax,%rax
je     11a4 <git_current_commit+0x64>
xor    %r14d,%r14d
mov    %r15,%rsp
jmp    1196 <git_current_commit+0x56>
xor    %r14d,%r14d
mov    %r14,%rax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe55(%rip),%rdi
call   1030 <git__pipe_read@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <chdir@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
jmp    118e <git_current_commit+0x4e>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [19 x i8] c"git rev-parse HEAD\00"
define i8* @git_current_commit(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i8* null, i8** %2
br label %34
11: ; preds = %1
%12 = load i32, i32* @PATH_MAX
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %4
%15 = alloca i8, i64 %13
store i64 %13, i64* %5
%16 = load i32, i32* @PATH_MAX
%17 = call i8* @getcwd(i8* %15, i32 %16)
%18 = icmp ne i8* %17, %15
br i1 %18, label %19, label %20
19: ; preds = %11
store i8* null, i8** %2
store i32 1, i32* %6
br label %32
20: ; preds = %11
%21 = load i8*, i8** %3
%22 = call i64 @chdir(i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i8* null, i8** %2
store i32 1, i32* %6
br label %32
25: ; preds = %20
%26 = call i8* @git__pipe_read(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i8* %26, i8** %7
%27 = call i64 @chdir(i8* %15)
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i8*, i8** %7
store i8* %31, i8** %2
store i32 1, i32* %6
br label %32
32: ; preds = %25, %24, %19
%33 = load i8*, i8** %4
br label %34
34: ; preds = %32, %10
%35 = load i8*, i8** %2
ret i8* %35
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [19 x i8] c"git rev-parse HEAD\00"
define i8* @git_current_commit(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %22, label %3
3: ; preds = %1
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = tail call i8* @llvm.stacksave()
%7 = alloca i8, i64 %5
%8 = load i32, i32* @PATH_MAX
%9 = call i8* @getcwd(i8* %7, i32 %8)
%10 = icmp eq i8* %9, %7
br i1 %10, label %11, label %20
11: ; preds = %3
%12 = call i64 @chdir(i8* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = call i8* @git__pipe_read(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%16 = call i64 @chdir(i8* %7)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
br label %20
20: ; preds = %11, %3, %14
%21 = phi i8* [ %15, %14 ], [ null, %3 ], [ null, %11 ]
br label %22
22: ; preds = %1, %20
%23 = phi i8* [ %21, %20 ], [ null, %1 ]
ret i8* %23
}