#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 main(void) {
  int numbers, count;
  int diff;
  printf("How many numbers are you subtracting?");
  scanf("%d", &numbers);
  int *subtract = malloc(sizeof(int) * numbers);
  if (subtract == NULL) {
    printf("Malloc failed!");
    return 1;
  }
  printf("Enter your numbers: ");
  scanf("%d", diff);
  for (count = 1; count < numbers; count++) {
    scanf("%d", subtract);
    diff = diff - (*subtract);
  }
  printf("The difference is %d.", diff);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
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    1197 <main+0x67>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    120d <main+0xdd>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f5 <main+0xc5>
mov    -0x18(%rbp),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x10(%rbp),%eax
mov    -0x18(%rbp),%rcx
sub    (%rcx),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11bd <main+0x8d>
mov    -0x10(%rbp),%esi
lea    0xe4e(%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   %rbx
push   %rax
lea    0xec2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeda(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x4(%rsp),%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11bd <main+0x8d>
mov    %rax,%r15
lea    0xec5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea5(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    $0x1,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
sub    (%r15),%ebp
add    $0x1,%ebx
cmp    0x4(%rsp),%ebx
jl     1190 <main+0x60>
lea    0xe9d(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11d0 <main+0xa0>
lea    0xe65(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"How many numbers are you subtracting?\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 = [22 x i8] c"The difference 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
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @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 %38
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%19 = load i32, i32* %4
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 1, i32* %3
br label %21
21: ; preds = %32, %17
%22 = load i32, i32* %3
%23 = load i32, i32* %2
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = load i32*, i32** %5
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %26)
%28 = load i32, i32* %4
%29 = load i32*, i32** %5
%30 = load i32, i32* %29
%31 = sub nsw i32 %28, %30
store i32 %31, i32* %4
br label %32
32: ; preds = %25
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
br label %21
35: ; preds = %21
%36 = load i32, i32* %4
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %36)
store i32 0, i32* %1
br label %38
38: ; preds = %35, %15
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str = [38 x i8] c"How many numbers are you subtracting?\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 = [22 x i8] c"The difference 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 ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @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 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 undef)
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, 1
br label %16
16: ; preds = %11, %16
%17 = phi i32 [ %21, %16 ], [ undef, %11 ]
%18 = phi i32 [ %22, %16 ], [ 1, %11 ]
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%20 = load i32, i32* %7
%21 = sub nsw i32 %17, %20
%22 = add nuw nsw i32 %18, 1
%23 = load i32, i32* %1
%24 = icmp slt i32 %22, %23
br i1 %24, label %16, label %25
25: ; preds = %16
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %21)
br label %27
27: ; preds = %25, %9
%28 = phi i32 [ 1, %9 ], [ 0, %25 ]
ret i32 %28
}