#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ calculateFoo(double *, int, int);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  if (argc < 3)
    return EXIT_FAILURE;
  int a = atoi(argv[1]);
  int b = atoi(argv[2]);
  double *foo = NULL;
  if (b > 0) {
    foo = (double *)malloc(b * sizeof(double));
    if (!foo) {
      printf("Memory allocation error");
      return 2;
    }
  } else
    return 3;
  calculateFoo(foo, b, a);
  free(foo);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1181 <main+0x31>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    121e <main+0xce>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11ee <main+0x9e>
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e9 <main+0x99>
lea    0xe28(%rip),%rdi
call   1050 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    121e <main+0xce>
jmp    11fa <main+0xaa>
movl   $0x3,-0x4(%rbp)
jmp    121e <main+0xce>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <calculateFoo@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jg     1162 <main+0x12>
mov    0x2e80(%rip),%rax
jmp    11b0 <main+0x60>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1070 <atoi@plt>
test   %eax,%eax
jle    11b4 <main+0x64>
mov    %eax,%ebx
lea    0x0(,%rbx,8),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11bb <main+0x6b>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
call   1040 <calculateFoo@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
jmp    11cc <main+0x7c>
mov    $0x3,%eax
jmp    11cc <main+0x7c>
lea    0xe3e(%rip),%rdi
call   1050 <printf@plt>
mov    $0x2,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [24 x i8] c"Memory allocation error\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load i32, i32* @EXIT_FAILURE
br label %25
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %6
%15 = shl i32 %12, 3
%16 = tail call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to double*
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %25
21: ; preds = %14
%22 = tail call i32 @calculateFoo(double* %17, i32 %12, i32 %9)
%23 = tail call i32 @free(double* %17)
%24 = load i32, i32* @EXIT_SUCCESS
br label %25
25: ; preds = %19, %21, %6, %4
%26 = phi i32 [ %5, %4 ], [ %24, %21 ], [ 2, %19 ], [ 3, %6 ]
ret i32 %26
}