#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 */
size_t append_to_buffer(char *, size_t, size_t, int /*<<< orphan*/, char *);
scalar_t__ malloc(size_t);
char *item_stats_buckets(int *bytes) {
  size_t bufsize = (2 * 1024 * 1024), offset = 0;
  char *buf = (char *)malloc(bufsize);
  int i, j;
  char terminator[] = "END\r\n";
  *bytes = 0;
  if (buf == 0) {
    return NULL;
  }
  (void)i;
  (void)j;
  offset = append_to_buffer(buf, bufsize, offset, 0, terminator);
  *bytes = offset;
  return buf;
}


x86 assembly (clang, -O0):
<item_stats_buckets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x200000,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    0xeb1(%rip),%eax
mov    %eax,-0x36(%rbp)
mov    0xeab(%rip),%ax
mov    %ax,-0x32(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
cmpq   $0x0,-0x28(%rbp)
jne    117f <item_stats_buckets+0x5f>
movq   $0x0,-0x8(%rbp)
jmp    11ae <item_stats_buckets+0x8e>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x36(%rbp),%r8
xor    %ecx,%ecx
call   1030 <append_to_buffer@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<item_stats_buckets>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x200000,%edi
call   1040 <malloc@plt>
movw   $0xa,0x4(%rsp)
movl   $0xd444e45,(%rsp)
movl   $0x0,(%r14)
test   %rax,%rax
je     1167 <item_stats_buckets+0x47>
mov    %rax,%rbx
mov    %rsp,%r8
mov    $0x200000,%esi
mov    %rax,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <append_to_buffer@plt>
mov    %eax,(%r14)
jmp    1169 <item_stats_buckets+0x49>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.item_stats_buckets.terminator = [6 x i8] c"END\0D\0A\00"
define i8* @item_stats_buckets(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [6 x i8]
store i32* %0, i32** %3
store i64 2097152, i64* %4
store i64 0, i64* %5
%10 = load i64, i64* %4
%11 = call i64 @malloc(i64 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %6
%13 = bitcast [6 x i8]* %9 to i8*
%14 = load i32*, i32** %3
store i32 0, i32* %14
%15 = load i8*, i8** %6
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %1
store i8* null, i8** %2
br label %30
18: ; preds = %1
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = load i8*, i8** %6
%22 = load i64, i64* %4
%23 = load i64, i64* %5
%24 = getelementptr inbounds [6 x i8], [6 x i8]* %9, i64 0, i64 0
%25 = call i64 @append_to_buffer(i8* %21, i64 %22, i64 %23, i32 0, i8* %24)
store i64 %25, i64* %5
%26 = load i64, i64* %5
%27 = trunc i64 %26 to i32
%28 = load i32*, i32** %3
store i32 %27, i32* %28
%29 = load i8*, i8** %6
store i8* %29, i8** %2
br label %30
30: ; preds = %18, %17
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
@__const.item_stats_buckets.terminator = [6 x i8] c"END\0D\0A\00"
define i8* @item_stats_buckets(i32* nocapture writeonly %0) {
%2 = alloca [6 x i8]
%3 = tail call i64 @malloc(i64 2097152)
%4 = inttoptr i64 %3 to i8*
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
store i32 0, i32* %0
%6 = icmp eq i64 %3, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = call i64 @append_to_buffer(i8* %4, i64 2097152, i64 0, i32 0, i8* %5)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %0
br label %10
10: ; preds = %1, %7
%11 = phi i8* [ %4, %7 ], [ null, %1 ]
ret i8* %11
}