#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*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int func(int n) {
  int i = 0;
  int ret = 0;
  int *p = NULL;
  do {
    p = (int *)malloc(sizeof(int) * n);
    if (p == NULL) {
      ret = -1;
      break;
    }
    if (n < 0) {
      ret = -1;
      break;
    }
    for (i = 0; i < n; i++) {
      p[i] = (i + 1) * 10;
      printf("%d ", p[i]);
    }
  } while (0);
  free(p);
  return ret;
}


x86 assembly (clang, -O0):
<func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117b <func+0x4b>
movl   $0xffffffff,-0xc(%rbp)
jmp    11e2 <func+0xb2>
cmpl   $0x0,-0x4(%rbp)
jge    1191 <func+0x61>
movl   $0xffffffff,-0xc(%rbp)
jmp    11e2 <func+0xb2>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11dd <func+0xad>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
imul   $0xa,%eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe36(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1198 <func+0x68>
jmp    11e2 <func+0xb2>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0x0(,%rbp,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    $0xffffffff,%r14d
test   %ebp,%ebp
js     119f <func+0x6f>
test   %r12,%r12
je     119f <func+0x6f>
test   %ebp,%ebp
je     119c <func+0x6c>
mov    %ebp,%r13d
mov    $0xa,%ebp
xor    %r14d,%r14d
lea    0xe8f(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,(%r12,%rbx,4)
add    $0x1,%rbx
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
add    $0xa,%ebp
cmp    %rbx,%r13
jne    1180 <func+0x50>
jmp    119f <func+0x6f>
xor    %r14d,%r14d
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
define i32 @func(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32* null, i32** %5
br label %6
6: ; preds = %1
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = mul i64 4, %8
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %5
%13 = load i32*, i32** %5
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %6
store i32 -1, i32* %4
br label %43
16: ; preds = %6
%17 = load i32, i32* %2
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 -1, i32* %4
br label %43
20: ; preds = %16
store i32 0, i32* %3
br label %21
21: ; preds = %39, %20
%22 = load i32, i32* %3
%23 = load i32, i32* %2
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %42
25: ; preds = %21
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
%28 = mul nsw i32 %27, 10
%29 = load i32*, i32** %5
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
store i32 %28, i32* %32
%33 = load i32*, i32** %5
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %25
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %21
42: ; preds = %21
br label %43
43: ; preds = %42, %19, %15
%44 = load i32*, i32** %5
%45 = call i32 @free(i32* %44)
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
define i32 @func(i32 %0) {
%2 = shl i32 %0, 2
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i32*
%5 = icmp eq i64 %3, 0
%6 = icmp slt i32 %0, 0
%7 = or i1 %6, %5
br i1 %7, label %20, label %8
8: ; preds = %1
%9 = icmp eq i32 %0, 0
br i1 %9, label %20, label %10
10: ; preds = %8
%11 = zext i32 %0 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %14, %12 ]
%14 = add nuw nsw i64 %13, 1
%15 = getelementptr inbounds i32, i32* %4, i64 %13
%16 = trunc i64 %14 to i32
%17 = mul i32 %16, 10
store i32 %17, i32* %15
%18 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = icmp eq i64 %14, %11
br i1 %19, label %20, label %12
20: ; preds = %12, %8, %1
%21 = phi i32 [ -1, %1 ], [ 0, %8 ], [ 0, %12 ]
%22 = tail call i32 @free(i32* %4)
ret i32 %21
}