#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ hdbm_file_copy(char const *, char const *);
int /*<<< orphan*/ hdbm_free(char *, int);
char *hdbm_malloc(size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ unlink(char *);
int hdbm_file_compress(const char *filename) {
  int l = (int)strlen(filename) + 5;
  char *tmp = hdbm_malloc((size_t)l);
  if (!tmp) {
    (void)fprintf(stderr, "hdbm_file_compress: no memory\n");
    return 0;
  }
  strcpy(tmp, filename);
  tmp[l - 5] = '.';
  tmp[l - 4] = 't';
  tmp[l - 3] = 'm';
  tmp[l - 2] = 'p';
  tmp[l - 1] = 0;
  if (!hdbm_file_copy(filename, tmp)) {
    (void)fprintf(stderr, "hdbm_file_compress: copy to %s failed\n", tmp);
    return 0;
  }
  if (!hdbm_file_copy(tmp, filename)) {
    (void)fprintf(stderr, "hdbm_file_compress: copy from %s failed\n", tmp);
    (void)fprintf(stderr, "hdbm_file_compress: copy manually to recover\n");
    return 0;
  }
  (void)unlink(tmp);
  hdbm_free(tmp, l);
  return 1;
}


x86 assembly (clang, -O0):
<hdbm_file_compress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x5,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rdi
call   1080 <hdbm_malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c6 <hdbm_file_compress+0x56>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d5 <hdbm_file_compress+0x165>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x5,%ecx
movslq %ecx,%rcx
movb   $0x2e,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x4,%ecx
movslq %ecx,%rcx
movb   $0x74,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x6d,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x70,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <hdbm_file_copy@plt>
cmp    $0x0,%eax
jne    1265 <hdbm_file_compress+0xf5>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d5 <hdbm_file_compress+0x165>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <hdbm_file_copy@plt>
cmp    $0x0,%eax
jne    12b9 <hdbm_file_compress+0x149>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdb7(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d5 <hdbm_file_compress+0x165>
mov    -0x20(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <hdbm_free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hdbm_file_compress>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %rax,%rbp
lea    0x5(%rax),%r14d
movslq %r14d,%rdi
call   1080 <hdbm_malloc@plt>
test   %rax,%rax
je     123f <hdbm_file_compress+0xcf>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rax
shl    $0x20,%rax
movslq %ebp,%rcx
movb   $0x2e,(%rbx,%rcx,1)
movabs $0x100000000,%rcx
add    %rax,%rcx
sar    $0x20,%rcx
movb   $0x74,(%rbx,%rcx,1)
movabs $0x200000000,%rcx
add    %rax,%rcx
sar    $0x20,%rcx
movb   $0x6d,(%rbx,%rcx,1)
movabs $0x300000000,%rcx
add    %rax,%rcx
sar    $0x20,%rcx
movb   $0x70,(%rbx,%rcx,1)
movabs $0x400000000,%rcx
add    %rax,%rcx
sar    $0x20,%rcx
movb   $0x0,(%rbx,%rcx,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <hdbm_file_copy@plt>
test   %eax,%eax
je     1253 <hdbm_file_compress+0xe3>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <hdbm_file_copy@plt>
test   %eax,%eax
je     1271 <hdbm_file_compress+0x101>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1060 <hdbm_free@plt>
mov    $0x1,%ebp
jmp    129f <hdbm_file_compress+0x12f>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
xor    %ebp,%ebp
jmp    1298 <hdbm_file_compress+0x128>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xdbc(%rip),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    129f <hdbm_file_compress+0x12f>
mov    0x2d68(%rip),%r14
mov    (%r14),%edi
lea    0xdc4(%rip),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r14),%edi
lea    0xdd7(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"hdbm_file_compress: no memory\0A\00"
@.str.1 = [39 x i8] c"hdbm_file_compress: copy to %s failed\0A\00"
@.str.2 = [41 x i8] c"hdbm_file_compress: copy from %s failed\0A\00"
@.str.3 = [46 x i8] c"hdbm_file_compress: copy manually to recover\0A\00"
define i32 @hdbm_file_compress(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
%8 = trunc i64 %7 to i32
%9 = add nsw i32 %8, 5
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = call i8* @hdbm_malloc(i64 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %72
18: ; preds = %1
%19 = load i8*, i8** %5
%20 = load i8*, i8** %3
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = load i8*, i8** %5
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 46, i8* %26
%27 = load i8*, i8** %5
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
store i8 116, i8* %31
%32 = load i8*, i8** %5
%33 = load i32, i32* %4
%34 = sub nsw i32 %33, 3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
store i8 109, i8* %36
%37 = load i8*, i8** %5
%38 = load i32, i32* %4
%39 = sub nsw i32 %38, 2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 112, i8* %41
%42 = load i8*, i8** %5
%43 = load i32, i32* %4
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
store i8 0, i8* %46
%47 = load i8*, i8** %3
%48 = load i8*, i8** %5
%49 = call i32 @hdbm_file_copy(i8* %47, i8* %48)
%50 = icmp ne i32 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %18
%52 = load i32, i32* @stderr
%53 = load i8*, i8** %5
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %53)
store i32 0, i32* %2
br label %72
55: ; preds = %18
%56 = load i8*, i8** %5
%57 = load i8*, i8** %3
%58 = call i32 @hdbm_file_copy(i8* %56, i8* %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %66, label %60
60: ; preds = %55
%61 = load i32, i32* @stderr
%62 = load i8*, i8** %5
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %62)
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %2
br label %72
66: ; preds = %55
%67 = load i8*, i8** %5
%68 = call i32 @unlink(i8* %67)
%69 = load i8*, i8** %5
%70 = load i32, i32* %4
%71 = call i32 @hdbm_free(i8* %69, i32 %70)
store i32 1, i32* %2
br label %72
72: ; preds = %66, %60, %51, %15
%73 = load i32, i32* %2
ret i32 %73
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"hdbm_file_compress: no memory\0A\00"
@.str.1 = [39 x i8] c"hdbm_file_compress: copy to %s failed\0A\00"
@.str.2 = [41 x i8] c"hdbm_file_compress: copy from %s failed\0A\00"
@.str.3 = [46 x i8] c"hdbm_file_compress: copy manually to recover\0A\00"
define i32 @hdbm_file_compress(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = add nsw i32 %3, 5
%5 = sext i32 %4 to i64
%6 = tail call i8* @hdbm_malloc(i64 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %44
11: ; preds = %1
%12 = tail call i32 @strcpy(i8* %6, i8* %0)
%13 = shl i64 %2, 32
%14 = ashr exact i64 %13, 32
%15 = getelementptr inbounds i8, i8* %6, i64 %14
store i8 46, i8* %15
%16 = add i64 %13, 4294967296
%17 = ashr exact i64 %16, 32
%18 = getelementptr inbounds i8, i8* %6, i64 %17
store i8 116, i8* %18
%19 = add i64 %13, 8589934592
%20 = ashr exact i64 %19, 32
%21 = getelementptr inbounds i8, i8* %6, i64 %20
store i8 109, i8* %21
%22 = add i64 %13, 12884901888
%23 = ashr exact i64 %22, 32
%24 = getelementptr inbounds i8, i8* %6, i64 %23
store i8 112, i8* %24
%25 = add i64 %13, 17179869184
%26 = ashr exact i64 %25, 32
%27 = getelementptr inbounds i8, i8* %6, i64 %26
store i8 0, i8* %27
%28 = tail call i32 @hdbm_file_copy(i8* %0, i8* %6)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %11
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %44
33: ; preds = %11
%34 = tail call i32 @hdbm_file_copy(i8* %6, i8* %0)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
br label %44
41: ; preds = %33
%42 = tail call i32 @unlink(i8* %6)
%43 = tail call i32 @hdbm_free(i8* %6, i32 %4)
br label %44
44: ; preds = %41, %36, %30, %8
%45 = phi i32 [ 1, %41 ], [ 0, %36 ], [ 0, %30 ], [ 0, %8 ]
ret i32 %45
}