#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 *md_alloc_int(int length) {
  int *field = NULL;
  int i;
  if (length < 1) {
    return (NULL);
  }
  if ((field = (int *)malloc(length * sizeof(int))) == NULL) {
    return (NULL);
  } else {
    for (i = 0; i < length; i++) {
      field[i] = 0;
    }
    return (field);
  }
}


x86 assembly (clang, -O0):
<md_alloc_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jge    113a <md_alloc_int+0x2a>
movq   $0x0,-0x8(%rbp)
jmp    119c <md_alloc_int+0x8c>
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1164 <md_alloc_int+0x54>
movq   $0x0,-0x8(%rbp)
jmp    119c <md_alloc_int+0x8c>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1194 <md_alloc_int+0x84>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116b <md_alloc_int+0x5b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<md_alloc_int>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    1150 <md_alloc_int+0x30>
mov    %edi,%ebx
lea    0x0(,%rbx,4),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1150 <md_alloc_int+0x30>
mov    %rax,%r14
mov    %ebx,%edx
shl    $0x2,%rdx
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
jmp    1153 <md_alloc_int+0x33>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32* @md_alloc_int(i32 %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 %0, i32* %3
store i32* null, i32** %4
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 1
br i1 %7, label %8, label %9
8: ; preds = %1
store i32* null, i32** %2
br label %33
9: ; preds = %1
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 4
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %4
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %9
store i32* null, i32** %2
br label %33
18: ; preds = %9
store i32 0, i32* %5
br label %19
19: ; preds = %28, %18
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = load i32*, i32** %4
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
store i32 0, i32* %27
br label %28
28: ; preds = %23
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %19
31: ; preds = %19
%32 = load i32*, i32** %4
store i32* %32, i32** %2
br label %33
33: ; preds = %31, %17, %8
%34 = load i32*, i32** %2
ret i32* %34
}

LLVM IR (-O2):
define i32* @md_alloc_int(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = shl i32 %0, 2
%5 = tail call i64 @malloc(i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = inttoptr i64 %5 to i8*
%9 = inttoptr i64 %5 to i32*
%10 = zext i32 %0 to i64
%11 = shl nuw nsw i64 %10, 2
br label %12
12: ; preds = %7, %3, %1
%13 = phi i32* [ null, %1 ], [ null, %3 ], [ %9, %7 ]
ret i32* %13
}