#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 DataMap {
  int dummy;
};
typedef int /*<<< orphan*/ gzFile;

/* Variables and functions */
char *DataMapEncodeBuffer(struct DataMap *, int *);
int /*<<< orphan*/ free(char *);
int gzwrite(int /*<<< orphan*/, char *, int);
int DataMapWriteZ(gzFile file, struct DataMap *ptr) {
  char *buf = NULL;
  int sze = 0, st = 0, cnt = 0;
  buf = DataMapEncodeBuffer(ptr, &sze);
  if (buf == NULL)
    return -1;
  while (cnt < sze) {
    st = gzwrite(file, buf + cnt, sze - cnt);
    if (st <= 0)
      break;
    cnt += st;
  }
  if (cnt < sze)
    return st;
  free(buf);
  return sze;
}


x86 assembly (clang, -O0):
<DataMapWriteZ>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <DataMapEncodeBuffer@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1184 <DataMapWriteZ+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f4 <DataMapWriteZ+0xc4>
jmp    1189 <DataMapWriteZ+0x59>
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ce <DataMapWriteZ+0x9e>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
sub    -0x24(%rbp),%edx
call   1050 <gzwrite@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     11c0 <DataMapWriteZ+0x90>
jmp    11ce <DataMapWriteZ+0x9e>
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1189 <DataMapWriteZ+0x59>
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e5 <DataMapWriteZ+0xb5>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f4 <DataMapWriteZ+0xc4>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DataMapWriteZ>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rax
mov    %edi,%ebp
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
call   1040 <DataMapEncodeBuffer@plt>
test   %rax,%rax
je     1190 <DataMapWriteZ+0x60>
mov    %rax,%r14
mov    0xc(%rsp),%edx
xor    %ebx,%ebx
test   %edx,%edx
jle    1197 <DataMapWriteZ+0x67>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %ebx,%rax
lea    (%r14,%rax,1),%rsi
sub    %eax,%edx
mov    %ebp,%edi
call   1050 <gzwrite@plt>
test   %eax,%eax
jle    11b2 <DataMapWriteZ+0x82>
add    %eax,%ebx
mov    0xc(%rsp),%edx
cmp    %ebx,%edx
jg     1170 <DataMapWriteZ+0x40>
jmp    1199 <DataMapWriteZ+0x69>
mov    $0xffffffff,%eax
jmp    11a9 <DataMapWriteZ+0x79>
xor    %eax,%eax
cmp    %edx,%ebx
jl     11a9 <DataMapWriteZ+0x79>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0xc(%rsp),%edx
cmp    %edx,%ebx
jge    119d <DataMapWriteZ+0x6d>
jmp    11a9 <DataMapWriteZ+0x79>

LLVM IR (-O0):
%struct.DataMap = type { i32 }
define i32 @DataMapWriteZ(i32 %0, %struct.DataMap* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.DataMap*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store %struct.DataMap* %1, %struct.DataMap** %5
store i8* null, i8** %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%10 = load %struct.DataMap*, %struct.DataMap** %5
%11 = call i8* @DataMapEncodeBuffer(%struct.DataMap* %10, i32* %7)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %47
15: ; preds = %2
br label %16
16: ; preds = %33, %15
%17 = load i32, i32* %9
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %37
20: ; preds = %16
%21 = load i32, i32* %4
%22 = load i8*, i8** %6
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i32, i32* %7
%27 = load i32, i32* %9
%28 = sub nsw i32 %26, %27
%29 = call i32 @gzwrite(i32 %21, i8* %25, i32 %28)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp sle i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %20
br label %37
33: ; preds = %20
%34 = load i32, i32* %8
%35 = load i32, i32* %9
%36 = add nsw i32 %35, %34
store i32 %36, i32* %9
br label %16
37: ; preds = %32, %16
%38 = load i32, i32* %9
%39 = load i32, i32* %7
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = load i32, i32* %8
store i32 %42, i32* %3
br label %47
43: ; preds = %37
%44 = load i8*, i8** %6
%45 = call i32 @free(i8* %44)
%46 = load i32, i32* %7
store i32 %46, i32* %3
br label %47
47: ; preds = %43, %41, %14
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
%struct.DataMap = type { i32 }
define i32 @DataMapWriteZ(i32 %0, %struct.DataMap* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = call i8* @DataMapEncodeBuffer(%struct.DataMap* %1, i32* %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %32, label %7
7: ; preds = %2
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %7, %20
%11 = phi i32 [ %22, %20 ], [ %8, %7 ]
%12 = phi i32 [ %21, %20 ], [ 0, %7 ]
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %5, i64 %13
%15 = sub nsw i32 %11, %12
%16 = call i32 @gzwrite(i32 %0, i8* %14, i32 %15)
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = load i32, i32* %3
br label %24
20: ; preds = %10
%21 = add nsw i32 %16, %12
%22 = load i32, i32* %3
%23 = icmp sgt i32 %22, %21
br i1 %23, label %10, label %24
24: ; preds = %20, %18, %7
%25 = phi i32 [ %8, %7 ], [ %19, %18 ], [ %22, %20 ]
%26 = phi i32 [ 0, %7 ], [ %12, %18 ], [ %21, %20 ]
%27 = phi i32 [ 0, %7 ], [ %16, %18 ], [ %16, %20 ]
%28 = icmp slt i32 %26, %25
br i1 %28, label %32, label %29
29: ; preds = %24
%30 = call i32 @free(i8* %5)
%31 = load i32, i32* %3
br label %32
32: ; preds = %24, %2, %29
%33 = phi i32 [ %31, %29 ], [ -1, %2 ], [ %27, %24 ]
ret i32 %33
}