#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 *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int numbers, count;
  int product = 1;
  printf("How many numbers do you want to multiply?");
  scanf("%d", &numbers);
  int *multiply = malloc(sizeof(int) * numbers);
  if (multiply == NULL) {
    printf("Malloc failed!");
    return 1;
  }
  printf("Enter your numbers: ");
  for (count = 0; count < numbers; count++) {
    scanf("%d", multiply);
    product = product * (*multiply);
  }
  printf("The product is %d", product);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf02(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119c <main+0x6c>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1200 <main+0xd0>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e8 <main+0xb8>
mov    -0x18(%rbp),%rsi
lea    0xe95(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%eax
mov    -0x18(%rbp),%rcx
imul   (%rcx),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b1 <main+0x81>
mov    -0x10(%rbp),%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebd(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf0c(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11bb <main+0x8b>
mov    %rax,%r12
lea    0xec3(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11d1 <main+0xa1>
xor    %ebx,%ebx
mov    $0x1,%ebp
lea    0xec8(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
imul   (%r12),%ebp
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
jl     11a0 <main+0x70>
jmp    11d6 <main+0xa6>
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%r14d
jmp    11e6 <main+0xb6>
mov    $0x1,%ebp
lea    0xe71(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"How many numbers do you want to multiply?\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [15 x i8] c"Malloc failed!\00"
@.str.3 = [21 x i8] c"Enter your numbers: \00"
@.str.4 = [18 x i8] c"The product is %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32 0, i32* %1
store i32 1, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = mul i64 4, %9
%11 = trunc i64 %10 to i32
%12 = call i32* @malloc(i32 %11)
store i32* %12, i32** %5
%13 = load i32*, i32** %5
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %36
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %19
19: ; preds = %30, %17
%20 = load i32, i32* %3
%21 = load i32, i32* %2
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load i32*, i32** %5
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %24)
%26 = load i32, i32* %4
%27 = load i32*, i32** %5
%28 = load i32, i32* %27
%29 = mul nsw i32 %26, %28
store i32 %29, i32* %4
br label %30
30: ; preds = %23
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %19
33: ; preds = %19
%34 = load i32, i32* %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %34)
store i32 0, i32* %1
br label %36
36: ; preds = %33, %15
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [42 x i8] c"How many numbers do you want to multiply?\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [15 x i8] c"Malloc failed!\00"
@.str.3 = [21 x i8] c"Enter your numbers: \00"
@.str.4 = [18 x i8] c"The product is %d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = shl i32 %5, 2
%7 = call i32* @malloc(i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %27
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%13 = load i32, i32* %1
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %11, %15
%16 = phi i32 [ %20, %15 ], [ 1, %11 ]
%17 = phi i32 [ %21, %15 ], [ 0, %11 ]
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%19 = load i32, i32* %7
%20 = mul nsw i32 %19, %16
%21 = add nuw nsw i32 %17, 1
%22 = load i32, i32* %1
%23 = icmp slt i32 %21, %22
br i1 %23, label %15, label %24
24: ; preds = %15, %11
%25 = phi i32 [ 1, %11 ], [ %20, %15 ]
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %24, %9
%28 = phi i32 [ 1, %9 ], [ 0, %24 ]
ret i32 %28
}