#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);
void obtain_list(int n, int *l, int **s) {
  int i;
  int c;
  if (n < 0)
    n = 0;
  *l = n;
  *s = (int *)malloc((*l) * sizeof(int));
  for (i = 0; i < *l; i++) {
    (*s)[i] = i;
  }
}


x86 assembly (clang, -O0):
<obtain_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1134 <obtain_list+0x24>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    118e <obtain_list+0x7e>
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1160 <obtain_list+0x50>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<obtain_list>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
xor    %eax,%eax
test   %edi,%edi
cmovs  %eax,%edi
mov    %edi,(%rsi)
shl    $0x2,%edi
call   1030 <malloc@plt>
mov    %rax,(%r14)
cmpl   $0x0,(%rbx)
jle    114f <obtain_list+0x3f>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ecx,(%rax,%rcx,4)
add    $0x1,%rcx
movslq (%rbx),%rdx
cmp    %rdx,%rcx
jl     1140 <obtain_list+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @obtain_list(i32 %0, i32* nocapture %1, i32** nocapture %2) {
%4 = icmp sgt i32 %0, 0
%5 = select i1 %4, i32 %0, i32 0
store i32 %5, i32* %1
%6 = shl i32 %5, 2
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %2
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %3, %11
%12 = phi i64 [ %15, %11 ], [ 0, %3 ]
%13 = getelementptr inbounds i32, i32* %8, i64 %12
%14 = trunc i64 %12 to i32
store i32 %14, i32* %13
%15 = add nuw nsw i64 %12, 1
%16 = load i32, i32* %1
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %11, label %19
19: ; preds = %11, %3
ret void
}