#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 */
scalar_t__ getenv(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char *);
char *sha1_file_name(const unsigned char *sha1) {
  int i;
  static char *name, *base;
  if (!base) {
    char *sha1_file_directory = getenv("SHA1_FILE_DIRECTORY") ?: ".git/objects";
    int len = strlen(sha1_file_directory);
    base = malloc(len + 60);
    memcpy(base, sha1_file_directory, len);
    memset(base + len, 0, 60);
    base[len] = '/';
    base[len + 3] = '/';
    name = base + len + 1;
  }
  for (i = 0; i < 20; i++) {
    static char hex[] = "0123456789abcdef";
    unsigned int val = sha1[i];
    char *pos = name + i * 2 + (i > 0);
    *pos++ = hex[val >> 4];
    *pos = hex[val & 0xf];
  }
  return base;
}


x86 assembly (clang, -O0):
<sha1_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,0x2f14(%rip)
jne    1230 <sha1_file_name+0xe0>
lea    0xe8f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1191 <sha1_file_name+0x41>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    11a1 <sha1_file_name+0x51>
lea    0xe7c(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    11a1 <sha1_file_name+0x51>
mov    -0x38(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x3c,%edi
call   1070 <malloc@plt>
mov    %rax,0x2eb1(%rip)
mov    0x2eaa(%rip),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <memcpy@plt>
mov    0x2e97(%rip),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
xor    %esi,%esi
mov    $0x3c,%edx
call   1050 <memset@plt>
mov    0x2e7d(%rip),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    0x2e6e(%rip),%rax
mov    -0x1c(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    0x2e5a(%rip),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,0x2e40(%rip)
movl   $0x0,-0xc(%rbp)
cmpl   $0x14,-0xc(%rbp)
jge    12c7 <sha1_file_name+0x177>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e19(%rip),%rax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
cmpl   $0x0,-0xc(%rbp)
setg   %cl
and    $0x1,%cl
movzbl %cl,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
shr    $0x4,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0x2dc5(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%eax
and    $0xf,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0x2da0(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1237 <sha1_file_name+0xe7>
mov    0x2daa(%rip),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sha1_file_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
mov    0x2ef6(%rip),%rax
test   %rax,%rax
je     1170 <sha1_file_name+0x20>
mov    0x2ee2(%rip),%rcx
jmp    11ed <sha1_file_name+0x9d>
lea    0xe89(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe8e(%rip),%r14
cmovne %rax,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    0x3c(%r15),%edi
call   1070 <malloc@plt>
mov    %rax,0x2eb3(%rip)
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1060 <memcpy@plt>
movslq %r15d,%r14
mov    0x2e9b(%rip),%rdi
add    %r14,%rdi
xor    %esi,%esi
mov    $0x3c,%edx
call   1050 <memset@plt>
mov    0x2e85(%rip),%rax
movb   $0x2f,(%rax,%r14,1)
movb   $0x2f,0x3(%rax,%r14,1)
lea    (%rax,%r14,1),%rcx
add    $0x1,%rcx
mov    %rcx,0x2e63(%rip)
xor    %edx,%edx
lea    0xe3a(%rip),%r8
cs nopw 0x0(%rax,%rax,1)
cmp    $0x1,%rdx
mov    %rcx,%rdi
sbb    $0xffffffffffffffff,%rdi
movzbl (%r12,%rdx,1),%esi
mov    %rsi,%rbx
shr    $0x4,%rbx
movzbl (%rbx,%r8,1),%ebx
mov    %bl,(%rdi,%rdx,2)
and    $0xf,%esi
movzbl (%rsi,%r8,1),%ebx
mov    %bl,0x1(%rdi,%rdx,2)
movzbl 0x1(%r12,%rdx,1),%esi
mov    %rsi,%rdi
shr    $0x4,%rdi
movzbl (%rdi,%r8,1),%ebx
mov    %bl,0x3(%rcx,%rdx,2)
and    $0xf,%esi
movzbl (%rsi,%r8,1),%ebx
mov    %bl,0x4(%rcx,%rdx,2)
add    $0x2,%rdx
cmp    $0x14,%rdx
jne    1200 <sha1_file_name+0xb0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@sha1_file_name.name = internal global i8* null
@sha1_file_name.base = internal global i8* null
@.str = [20 x i8] c"SHA1_FILE_DIRECTORY\00"
@.str.1 = [13 x i8] c".git/objects\00"
@sha1_file_name.hex = internal global [17 x i8] c"0123456789abcdef\00"
define i8* @sha1_file_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i8*, i8** @sha1_file_name.base
%9 = icmp ne i8* %8, null
br i1 %9, label %46, label %10
10: ; preds = %1
%11 = call i64 @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = inttoptr i64 %11 to i8*
br label %16
15: ; preds = %10
br label %16
16: ; preds = %15, %13
%17 = phi i8* [ %14, %13 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %15 ]
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 60
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** @sha1_file_name.base
%23 = load i8*, i8** @sha1_file_name.base
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = call i32 @memcpy(i8* %23, i8* %24, i32 %25)
%27 = load i8*, i8** @sha1_file_name.base
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = call i32 @memset(i8* %30, i32 0, i32 60)
%32 = load i8*, i8** @sha1_file_name.base
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 47, i8* %35
%36 = load i8*, i8** @sha1_file_name.base
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 3
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
store i8 47, i8* %40
%41 = load i8*, i8** @sha1_file_name.base
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = getelementptr inbounds i8, i8* %44, i64 1
store i8* %45, i8** @sha1_file_name.name
br label %46
46: ; preds = %16, %1
store i32 0, i32* %3
br label %47
47: ; preds = %80, %46
%48 = load i32, i32* %3
%49 = icmp slt i32 %48, 20
br i1 %49, label %50, label %83
50: ; preds = %47
%51 = load i8*, i8** %2
%52 = load i32, i32* %3
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
store i32 %56, i32* %6
%57 = load i8*, i8** @sha1_file_name.name
%58 = load i32, i32* %3
%59 = mul nsw i32 %58, 2
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %57, i64 %60
%62 = load i32, i32* %3
%63 = icmp sgt i32 %62, 0
%64 = zext i1 %63 to i32
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %61, i64 %65
store i8* %66, i8** %7
%67 = load i32, i32* %6
%68 = lshr i32 %67, 4
%69 = zext i32 %68 to i64
%70 = getelementptr inbounds [17 x i8], [17 x i8]* @sha1_file_name.hex, i64 0, i64 %69
%71 = load i8, i8* %70
%72 = load i8*, i8** %7
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %7
store i8 %71, i8* %72
%74 = load i32, i32* %6
%75 = and i32 %74, 15
%76 = zext i32 %75 to i64
%77 = getelementptr inbounds [17 x i8], [17 x i8]* @sha1_file_name.hex, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = load i8*, i8** %7
store i8 %78, i8* %79
br label %80
80: ; preds = %50
%81 = load i32, i32* %3
%82 = add nsw i32 %81, 1
store i32 %82, i32* %3
br label %47
83: ; preds = %47
%84 = load i8*, i8** @sha1_file_name.base
ret i8* %84
}

LLVM IR (-O2):
@sha1_file_name.name = internal unnamed_addr global i8* null
@sha1_file_name.base = internal unnamed_addr global i8* null
@.str = [20 x i8] c"SHA1_FILE_DIRECTORY\00"
@.str.1 = [13 x i8] c".git/objects\00"
@sha1_file_name.hex = internal unnamed_addr constant [17 x i8] c"0123456789abcdef\00"
define i8* @sha1_file_name(i8* nocapture %0) {
%2 = load i8*, i8** @sha1_file_name.base
%3 = icmp eq i8* %2, null
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = load i8*, i8** @sha1_file_name.name
br label %25
6: ; preds = %1
%7 = tail call i64 @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
%9 = inttoptr i64 %7 to i8*
%10 = select i1 %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %9
%11 = tail call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 60
%13 = tail call i8* @malloc(i32 %12)
store i8* %13, i8** @sha1_file_name.base
%14 = tail call i32 @memcpy(i8* %13, i8* %10, i32 %11)
%15 = load i8*, i8** @sha1_file_name.base
%16 = sext i32 %11 to i64
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = tail call i32 @memset(i8* %17, i32 0, i32 60)
%19 = load i8*, i8** @sha1_file_name.base
%20 = getelementptr inbounds i8, i8* %19, i64 %16
store i8 47, i8* %20
%21 = add nsw i32 %11, 3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
store i8 47, i8* %23
%24 = getelementptr inbounds i8, i8* %20, i64 1
store i8* %24, i8** @sha1_file_name.name
br label %25
25: ; preds = %4, %6
%26 = phi i8* [ %2, %4 ], [ %19, %6 ]
%27 = phi i8* [ %5, %4 ], [ %24, %6 ]
%28 = getelementptr inbounds i8, i8* %27, i64 1
br label %29
29: ; preds = %29, %25
%30 = phi i64 [ 0, %25 ], [ %63, %29 ]
%31 = getelementptr inbounds i8, i8* %0, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = shl nuw nsw i64 %30, 1
%35 = getelementptr inbounds i8, i8* %27, i64 %34
%36 = icmp ne i64 %30, 0
%37 = zext i1 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = lshr i32 %33, 4
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds [17 x i8], [17 x i8]* @sha1_file_name.hex, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = getelementptr inbounds i8, i8* %38, i64 1
store i8 %42, i8* %38
%44 = and i32 %33, 15
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds [17 x i8], [17 x i8]* @sha1_file_name.hex, i64 0, i64 %45
%47 = load i8, i8* %46
store i8 %47, i8* %43
%48 = or i64 %30, 1
%49 = getelementptr inbounds i8, i8* %0, i64 %48
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = shl nuw nsw i64 %48, 1
%53 = getelementptr inbounds i8, i8* %28, i64 %52
%54 = lshr i32 %51, 4
%55 = zext i32 %54 to i64
%56 = getelementptr inbounds [17 x i8], [17 x i8]* @sha1_file_name.hex, i64 0, i64 %55
%57 = load i8, i8* %56
%58 = getelementptr inbounds i8, i8* %53, i64 1
store i8 %57, i8* %53
%59 = and i32 %51, 15
%60 = zext i32 %59 to i64
%61 = getelementptr inbounds [17 x i8], [17 x i8]* @sha1_file_name.hex, i64 0, i64 %60
%62 = load i8, i8* %61
store i8 %62, i8* %58
%63 = add nuw nsw i64 %30, 2
%64 = icmp eq i64 %63, 20
br i1 %64, label %65, label %29
65: ; preds = %29
ret i8* %26
}