#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long);
scalar_t__ malloc(long);
int /*<<< orphan*/ stderr;
char *alloc_data(long data_size) {
  char *data;
  int i;
  data = (char *)malloc(data_size);
  if (data == NULL) {
    fprintf(stderr, "client: mmaloc %ld failed \n", data_size);
    exit(-1);
  }
  for (i = 0; i < data_size; i++)
    *(data + i) = 'P';
  return data;
}


x86 assembly (clang, -O0):
<alloc_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1177 <alloc_data+0x47>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe98(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    11a6 <alloc_data+0x76>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x50,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117e <alloc_data+0x4e>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_data>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <malloc@plt>
test   %rax,%rax
je     1174 <alloc_data+0x34>
mov    %rax,%rbx
test   %r14,%r14
jle    1169 <alloc_data+0x29>
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"client: mmaloc %ld failed \0A\00"
define i8* @alloc_data(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = call i64 @malloc(i64 %5)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i64, i64* %2
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i64 %12)
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %1
store i32 0, i32* %4
br label %16
16: ; preds = %26, %15
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = load i64, i64* %2
%20 = icmp slt i64 %18, %19
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 80, i8* %25
br label %26
26: ; preds = %21
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %16
29: ; preds = %16
%30 = load i8*, i8** %3
ret i8* %30
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"client: mmaloc %ld failed \0A\00"
define i8* @alloc_data(i64 %0) {
%2 = tail call i64 @malloc(i64 %0)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i64 %2, 0
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = icmp sgt i64 %0, 0
br i1 %6, label %7, label %12
7: ; preds = %5
br label %12
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i64 %0)
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %7, %5
ret i8* %3
}