#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 dirent {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int S_IRWXG;
int S_IRWXO;
int S_IRWXU;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ getHomeDir(char *);
int mkdir(char *, int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ print_logfile(int, int, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sha1_hash(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ umask(int);
char *proxy_cache(char *input_url, char *h_path, int semid) {
  umask(000);
  char homedir[30];
  char hash_url[41];
  int check = 0;
  struct dirent *pFile;
  DIR *pDir;
  strcpy(h_path, getHomeDir(homedir));
  strcat(h_path, "/proxy_cache");
  mkdir(h_path, S_IRWXU | S_IRWXG | S_IRWXO);
  sha1_hash(input_url, hash_url);
  strncat(h_path, "/", 1);
  strncat(h_path, hash_url, 1);
  mkdir(h_path, S_IRWXU | S_IRWXG | S_IRWXO);
  strncat(h_path, "/", 1);
  strncat(h_path, &hash_url[1], 1);
  check = mkdir(h_path, S_IRWXU | S_IRWXG | S_IRWXO);
  if (check == -1) {
    pDir = opendir(h_path);
    for (pFile = readdir(pDir); pFile; pFile = readdir(pDir)) {
      if (strcmp(pFile->d_name, &hash_url[2]) == 0) {
        print_logfile(1, semid, hash_url);
        check = 1;
        break;
      }
    }
    closedir(pDir);
  }
  strncat(h_path, "/", 1);
  strcat(h_path, &hash_url[2]);
  return h_path;
}


x86 assembly (clang, -O0):
<proxy_cache>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xor    %edi,%edi
call   10a0 <umask@plt>
movl   $0x0,-0x74(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x40(%rbp),%rdi
call   10c0 <getHomeDir@plt>
mov    -0x90(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xdef(%rip),%rsi
call   10e0 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
mov    0x2dae(%rip),%rax
or     (%rax),%esi
mov    0x2dbd(%rip),%rax
or     (%rax),%esi
call   1040 <mkdir@plt>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   10d0 <sha1_hash@plt>
mov    -0x10(%rbp),%rdi
lea    0xdbb(%rip),%rsi
mov    $0x1,%edx
call   1070 <strncat@plt>
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x1,%edx
call   1070 <strncat@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d67(%rip),%rax
mov    (%rax),%esi
mov    0x2d56(%rip),%rax
or     (%rax),%esi
mov    0x2d65(%rip),%rax
or     (%rax),%esi
call   1040 <mkdir@plt>
mov    -0x10(%rbp),%rdi
lea    0xd70(%rip),%rsi
mov    $0x1,%edx
call   1070 <strncat@plt>
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1,%edx
call   1070 <strncat@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d18(%rip),%rax
mov    (%rax),%esi
mov    0x2d07(%rip),%rax
or     (%rax),%esi
mov    0x2d16(%rip),%rax
or     (%rax),%esi
call   1040 <mkdir@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0xffffffff,-0x74(%rbp)
jne    1379 <proxy_cache+0x1b9>
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
je     136d <proxy_cache+0x1ad>
mov    -0x80(%rbp),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rsi
add    $0x2,%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1353 <proxy_cache+0x193>
mov    -0x14(%rbp),%esi
lea    -0x70(%rbp),%rdx
mov    $0x1,%edi
call   1060 <print_logfile@plt>
movl   $0x1,-0x74(%rbp)
jmp    136d <proxy_cache+0x1ad>
jmp    1358 <proxy_cache+0x198>
mov    -0x88(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x80(%rbp)
jmp    130e <proxy_cache+0x14e>
mov    -0x88(%rbp),%rdi
call   1080 <closedir@plt>
mov    -0x10(%rbp),%rdi
lea    0xc89(%rip),%rsi
mov    $0x1,%edx
call   1070 <strncat@plt>
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rsi
add    $0x2,%rsi
call   10e0 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proxy_cache>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %edx,0xc(%rsp)
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %edi,%edi
call   10a0 <umask@plt>
lea    0x40(%rsp),%rdi
call   10c0 <getHomeDir@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    0xe06(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <strcat@plt>
mov    0x2dd7(%rip),%r12
mov    0x2dc8(%rip),%r13
mov    0x0(%r13),%esi
or     (%r12),%esi
mov    0x2dd1(%rip),%r14
or     (%r14),%esi
mov    %rbx,%rdi
call   1040 <mkdir@plt>
lea    0x10(%rsp),%rbp
mov    %r15,%rdi
mov    %rbp,%rsi
call   10d0 <sha1_hash@plt>
lea    0xdcc(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1070 <strncat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1070 <strncat@plt>
mov    0x0(%r13),%esi
or     (%r12),%esi
or     (%r14),%esi
mov    %rbx,%rdi
call   1040 <mkdir@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1070 <strncat@plt>
lea    0x11(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1070 <strncat@plt>
mov    0x0(%r13),%esi
or     (%r12),%esi
or     (%r14),%esi
mov    %rbx,%rdi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    1308 <proxy_cache+0x148>
mov    %rbx,%rdi
call   1050 <opendir@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
mov    0xc(%rsp),%r14d
je     1300 <proxy_cache+0x140>
lea    0x12(%rsp),%r15
mov    (%rax),%edi
mov    %r15,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     12ee <proxy_cache+0x12e>
mov    %rbp,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
jne    12d0 <proxy_cache+0x110>
jmp    1300 <proxy_cache+0x140>
lea    0x10(%rsp),%rdx
mov    $0x1,%edi
mov    %r14d,%esi
call   1060 <print_logfile@plt>
mov    %rbp,%rdi
call   1080 <closedir@plt>
lea    0xcfe(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1070 <strncat@plt>
lea    0x12(%rsp),%rsi
mov    %rbx,%rdi
call   10e0 <strcat@plt>
mov    %rbx,%rax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [13 x i8] c"/proxy_cache\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str.1 = [2 x i8] c"/\00"
define i8* @proxy_cache(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [30 x i8]
%8 = alloca [41 x i8]
%9 = alloca i32
%10 = alloca %struct.dirent*
%11 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = call i32 @umask(i32 0)
store i32 0, i32* %9
%13 = load i8*, i8** %5
%14 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%15 = call i32 @getHomeDir(i8* %14)
%16 = call i32 @strcpy(i8* %13, i32 %15)
%17 = load i8*, i8** %5
%18 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %5
%20 = load i32, i32* @S_IRWXU
%21 = load i32, i32* @S_IRWXG
%22 = or i32 %20, %21
%23 = load i32, i32* @S_IRWXO
%24 = or i32 %22, %23
%25 = call i32 @mkdir(i8* %19, i32 %24)
%26 = load i8*, i8** %4
%27 = getelementptr inbounds [41 x i8], [41 x i8]* %8, i64 0, i64 0
%28 = call i32 @sha1_hash(i8* %26, i8* %27)
%29 = load i8*, i8** %5
%30 = call i32 @strncat(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%31 = load i8*, i8** %5
%32 = getelementptr inbounds [41 x i8], [41 x i8]* %8, i64 0, i64 0
%33 = call i32 @strncat(i8* %31, i8* %32, i32 1)
%34 = load i8*, i8** %5
%35 = load i32, i32* @S_IRWXU
%36 = load i32, i32* @S_IRWXG
%37 = or i32 %35, %36
%38 = load i32, i32* @S_IRWXO
%39 = or i32 %37, %38
%40 = call i32 @mkdir(i8* %34, i32 %39)
%41 = load i8*, i8** %5
%42 = call i32 @strncat(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%43 = load i8*, i8** %5
%44 = getelementptr inbounds [41 x i8], [41 x i8]* %8, i64 0, i64 1
%45 = call i32 @strncat(i8* %43, i8* %44, i32 1)
%46 = load i8*, i8** %5
%47 = load i32, i32* @S_IRWXU
%48 = load i32, i32* @S_IRWXG
%49 = or i32 %47, %48
%50 = load i32, i32* @S_IRWXO
%51 = or i32 %49, %50
%52 = call i32 @mkdir(i8* %46, i32 %51)
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %81
55: ; preds = %3
%56 = load i8*, i8** %5
%57 = call i32* @opendir(i8* %56)
store i32* %57, i32** %11
%58 = load i32*, i32** %11
%59 = call %struct.dirent* @readdir(i32* %58)
store %struct.dirent* %59, %struct.dirent** %10
br label %60
60: ; preds = %75, %55
%61 = load %struct.dirent*, %struct.dirent** %10
%62 = icmp ne %struct.dirent* %61, null
br i1 %62, label %63, label %78
63: ; preds = %60
%64 = load %struct.dirent*, %struct.dirent** %10
%65 = getelementptr inbounds %struct.dirent, %struct.dirent* %64, i32 0, i32 0
%66 = load i32, i32* %65
%67 = getelementptr inbounds [41 x i8], [41 x i8]* %8, i64 0, i64 2
%68 = call i64 @strcmp(i32 %66, i8* %67)
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %63
%71 = load i32, i32* %6
%72 = getelementptr inbounds [41 x i8], [41 x i8]* %8, i64 0, i64 0
%73 = call i32 @print_logfile(i32 1, i32 %71, i8* %72)
store i32 1, i32* %9
br label %78
74: ; preds = %63
br label %75
75: ; preds = %74
%76 = load i32*, i32** %11
%77 = call %struct.dirent* @readdir(i32* %76)
store %struct.dirent* %77, %struct.dirent** %10
br label %60
78: ; preds = %70, %60
%79 = load i32*, i32** %11
%80 = call i32 @closedir(i32* %79)
br label %81
81: ; preds = %78, %3
%82 = load i8*, i8** %5
%83 = call i32 @strncat(i8* %82, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%84 = load i8*, i8** %5
%85 = getelementptr inbounds [41 x i8], [41 x i8]* %8, i64 0, i64 2
%86 = call i32 @strcat(i8* %84, i8* %85)
%87 = load i8*, i8** %5
ret i8* %87
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [13 x i8] c"/proxy_cache\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str.1 = [2 x i8] c"/\00"
define i8* @proxy_cache(i8* %0, i8* returned %1, i32 %2) {
%4 = alloca [30 x i8]
%5 = alloca [41 x i8]
%6 = tail call i32 @umask(i32 0)
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [41 x i8], [41 x i8]* %5, i64 0, i64 0
%9 = call i32 @getHomeDir(i8* %7)
%10 = call i32 @strcpy(i8* %1, i32 %9)
%11 = call i32 @strcat(i8* %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @S_IRWXU
%13 = load i32, i32* @S_IRWXG
%14 = or i32 %13, %12
%15 = load i32, i32* @S_IRWXO
%16 = or i32 %14, %15
%17 = call i32 @mkdir(i8* %1, i32 %16)
%18 = call i32 @sha1_hash(i8* %0, i8* %8)
%19 = call i32 @strncat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%20 = call i32 @strncat(i8* %1, i8* %8, i32 1)
%21 = load i32, i32* @S_IRWXU
%22 = load i32, i32* @S_IRWXG
%23 = or i32 %22, %21
%24 = load i32, i32* @S_IRWXO
%25 = or i32 %23, %24
%26 = call i32 @mkdir(i8* %1, i32 %25)
%27 = call i32 @strncat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%28 = getelementptr inbounds [41 x i8], [41 x i8]* %5, i64 0, i64 1
%29 = call i32 @strncat(i8* %1, i8* %28, i32 1)
%30 = load i32, i32* @S_IRWXU
%31 = load i32, i32* @S_IRWXG
%32 = or i32 %31, %30
%33 = load i32, i32* @S_IRWXO
%34 = or i32 %32, %33
%35 = call i32 @mkdir(i8* %1, i32 %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %56
37: ; preds = %3
%38 = call i32* @opendir(i8* %1)
%39 = call %struct.dirent* @readdir(i32* %38)
%40 = icmp eq %struct.dirent* %39, null
br i1 %40, label %54, label %41
41: ; preds = %37
%42 = getelementptr inbounds [41 x i8], [41 x i8]* %5, i64 0, i64 2
br label %43
43: ; preds = %41, %51
%44 = phi %struct.dirent* [ %39, %41 ], [ %52, %51 ]
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i64 0, i32 0
%46 = load i32, i32* %45
%47 = call i64 @strcmp(i32 %46, i8* %42)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %43
%50 = call i32 @print_logfile(i32 1, i32 %2, i8* %8)
br label %54
51: ; preds = %43
%52 = call %struct.dirent* @readdir(i32* %38)
%53 = icmp eq %struct.dirent* %52, null
br i1 %53, label %54, label %43
54: ; preds = %51, %37, %49
%55 = call i32 @closedir(i32* %38)
br label %56
56: ; preds = %54, %3
%57 = call i32 @strncat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%58 = getelementptr inbounds [41 x i8], [41 x i8]* %5, i64 0, i64 2
%59 = call i32 @strcat(i8* %1, i8* %58)
ret i8* %1
}