#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int *apply_memory(size_t size) {
  size_t number_int = (size - 1) / (sizeof(int) * 8) + 1;
  int *block = (int *)malloc(sizeof(int) * number_int);
  if (NULL == block)
    perror("malloc failed.");
  else
    memset(block, 0, sizeof(int) * number_int);
  return block;
}


x86 assembly (clang, -O0):
<apply_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
sub    $0x1,%rax
shr    $0x5,%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    1180 <apply_memory+0x50>
lea    0xe8a(%rip),%rdi
call   1050 <perror@plt>
jmp    1195 <apply_memory+0x65>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apply_memory>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
shr    $0x3,%rbx
add    $0x4,%ebx
and    $0xfffffffc,%ebx
mov    %ebx,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     116b <apply_memory+0x3b>
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1030 <memset@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe8e(%rip),%rdi
call   1050 <perror@plt>
jmp    1160 <apply_memory+0x30>

LLVM IR (-O0):
@.str = [15 x i8] c"malloc failed.\00"
define i32* @apply_memory(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32*
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = sub i64 %5, 1
%7 = udiv i64 %6, 32
%8 = add i64 %7, 1
store i64 %8, i64* %3
%9 = load i64, i64* %3
%10 = mul i64 4, %9
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %4
%14 = load i32*, i32** %4
%15 = icmp eq i32* null, %14
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %24
18: ; preds = %1
%19 = load i32*, i32** %4
%20 = load i64, i64* %3
%21 = mul i64 4, %20
%22 = trunc i64 %21 to i32
%23 = call i32 @memset(i32* %19, i32 0, i32 %22)
br label %24
24: ; preds = %18, %16
%25 = load i32*, i32** %4
ret i32* %25
}

LLVM IR (-O2):
@.str = [15 x i8] c"malloc failed.\00"
define i32* @apply_memory(i64 %0) {
%2 = add i64 %0, 34359738367
%3 = lshr i64 %2, 3
%4 = trunc i64 %3 to i32
%5 = add i32 %4, 4
%6 = and i32 %5, -4
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %14
12: ; preds = %1
%13 = tail call i32 @memset(i32* %8, i32 0, i32 %6)
br label %14
14: ; preds = %12, %10
ret i32* %8
}