#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 atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
float rocket_equation(float, float, float);
int /*<<< orphan*/ scanf(char *, float *);
int main(int argc, char *argv[]) {
  float total_mass;
  float dry_mass;
  float sp_impulse;
  int num_stages = 0;
  float delta_v;
  float total_dv = 0;
  if (argc == 2) {
    num_stages = atoi(argv[1]);
  } else {
    printf("Usage:\n  delta-v [number of stages]\n");
  }
  if (num_stages == 1) {
    printf("Write the total mass of the vehicle: ");
    scanf("%f", &total_mass);
    printf("Write the mass of the vehicle without fuel: ");
    scanf("%f", &dry_mass);
    printf("Write the vehicle's engines specific impulse in seconds: ");
    scanf("%f", &sp_impulse);
    delta_v = rocket_equation(total_mass, dry_mass, sp_impulse);
    printf("The total Delta-V is %0.2f\n", delta_v);
  } else if (num_stages > 1) {
    for (int i = num_stages; i > 0; i--) {
      printf("Write the total mass of stage %i: ", i);
      scanf("%f", &total_mass);
      printf("Write the mass of stage %i without fuel: ", i);
      scanf("%f", &dry_mass);
      printf("Write stage %i engine's specific impulse in seconds: ", i);
      scanf("%f", &sp_impulse);
      delta_v = rocket_equation(total_mass, dry_mass, sp_impulse);
      total_dv = total_dv + delta_v;
    }
    printf("The total Delta-V is %0.2f\n", total_dv);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1184 <main+0x44>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    1192 <main+0x52>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x20(%rbp)
jne    122b <main+0xeb>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9a(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7c(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5e(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1050 <scanf@plt>
movss  -0x14(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
movss  -0x1c(%rbp),%xmm2
call   1030 <rocket_equation@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe96(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    12fa <main+0x1ba>
cmpl   $0x1,-0x20(%rbp)
jle    12f5 <main+0x1b5>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    12de <main+0x19e>
mov    -0x2c(%rbp),%esi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdee(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x2c(%rbp),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdcd(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x2c(%rbp),%esi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdac(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1050 <scanf@plt>
movss  -0x14(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
movss  -0x1c(%rbp),%xmm2
call   1030 <rocket_equation@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x28(%rbp),%xmm0
addss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    123b <main+0xfb>
movss  -0x28(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdc7(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    12fa <main+0x1ba>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    11ed <main+0x9d>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
cmp    $0x1,%eax
jne    11fe <main+0xae>
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe98(%rip),%rbx
lea    0x14(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xe99(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
movss  0x14(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
movss  0xc(%rsp),%xmm2
call   1030 <rocket_equation@plt>
jmp    12bc <main+0x16c>
lea    0xf3b(%rip),%rdi
call   1040 <puts@plt>
jmp    12ce <main+0x17e>
jle    12ce <main+0x17e>
mov    %eax,%ebx
xorps  %xmm0,%xmm0
lea    0xe16(%rip),%r15
lea    0xeb8(%rip),%r13
lea    0x10(%rsp),%rbp
lea    0xed6(%rip),%r14
lea    0xc(%rsp),%r12
nopl   0x0(%rax,%rax,1)
movss  %xmm0,0x8(%rsp)
lea    0xe6f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
lea    0x14(%rsp),%rsi
call   1060 <scanf@plt>
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1060 <scanf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <scanf@plt>
movss  0x14(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
movss  0xc(%rsp),%xmm2
call   1030 <rocket_equation@plt>
movss  0x8(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
movss  0x8(%rsp),%xmm0
lea    -0x1(%rbx),%eax
cmp    $0x1,%ebx
mov    %eax,%ebx
ja     1230 <main+0xe0>
cvtss2sd %xmm0,%xmm0
lea    0xdc9(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Usage:\0A delta-v [number of stages]\0A\00"
@.str.1 = [38 x i8] c"Write the total mass of the vehicle: \00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [45 x i8] c"Write the mass of the vehicle without fuel: \00"
@.str.4 = [58 x i8] c"Write the vehicle's engines specific impulse in seconds: \00"
@.str.5 = [28 x i8] c"The total Delta-V is %0.2f\0A\00"
@.str.6 = [35 x i8] c"Write the total mass of stage %i: \00"
@.str.7 = [42 x i8] c"Write the mass of stage %i without fuel: \00"
@.str.8 = [54 x i8] c"Write stage %i engine's specific impulse in seconds: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca i32
%10 = alloca float
%11 = alloca float
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store float 0.000000e+00, float* %11
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %9
br label %22
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = load i32, i32* %9
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %39
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %6)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %7)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %8)
%32 = load float, float* %6
%33 = load float, float* %7
%34 = load float, float* %8
%35 = call float @rocket_equation(float %32, float %33, float %34)
store float %35, float* %10
%36 = load float, float* %10
%37 = fpext float %36 to double
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), double %37)
br label %72
39: ; preds = %22
%40 = load i32, i32* %9
%41 = icmp sgt i32 %40, 1
br i1 %41, label %42, label %71
42: ; preds = %39
%43 = load i32, i32* %9
store i32 %43, i32* %12
br label %44
44: ; preds = %64, %42
%45 = load i32, i32* %12
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %67
47: ; preds = %44
%48 = load i32, i32* %12
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 %48)
%50 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %6)
%51 = load i32, i32* %12
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %51)
%53 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %7)
%54 = load i32, i32* %12
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0), i32 %54)
%56 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %8)
%57 = load float, float* %6
%58 = load float, float* %7
%59 = load float, float* %8
%60 = call float @rocket_equation(float %57, float %58, float %59)
store float %60, float* %10
%61 = load float, float* %11
%62 = load float, float* %10
%63 = fadd float %61, %62
store float %63, float* %11
br label %64
64: ; preds = %47
%65 = load i32, i32* %12
%66 = add nsw i32 %65, -1
store i32 %66, i32* %12
br label %44
67: ; preds = %44
%68 = load float, float* %11
%69 = fpext float %68 to double
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), double %69)
br label %71
71: ; preds = %67, %39
br label %72
72: ; preds = %71, %25
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [38 x i8] c"Write the total mass of the vehicle: \00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [45 x i8] c"Write the mass of the vehicle without fuel: \00"
@.str.4 = [58 x i8] c"Write the vehicle's engines specific impulse in seconds: \00"
@.str.5 = [28 x i8] c"The total Delta-V is %0.2f\0A\00"
@.str.6 = [35 x i8] c"Write the total mass of stage %i: \00"
@.str.7 = [42 x i8] c"Write the mass of stage %i without fuel: \00"
@.str.8 = [54 x i8] c"Write stage %i engine's specific impulse in seconds: \00"
@str = [36 x i8] c"Usage:\0A delta-v [number of stages]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = bitcast float* %3 to i8*
%7 = bitcast float* %4 to i8*
%8 = bitcast float* %5 to i8*
%9 = icmp eq i32 %0, 2
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %51
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %30
17: ; preds = %12
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %3)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %4)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %5)
%24 = load float, float* %3
%25 = load float, float* %4
%26 = load float, float* %5
%27 = call float @rocket_equation(float %24, float %25, float %26)
%28 = fpext float %27 to double
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), double %28)
br label %51
30: ; preds = %12
%31 = icmp sgt i32 %15, 1
br i1 %31, label %35, label %51
32: ; preds = %35
%33 = fpext float %48 to double
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), double %33)
br label %51
35: ; preds = %30, %35
%36 = phi i32 [ %49, %35 ], [ %15, %30 ]
%37 = phi float [ %48, %35 ], [ 0.000000e+00, %30 ]
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 %36)
%39 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %3)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %36)
%41 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %4)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0), i32 %36)
%43 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %5)
%44 = load float, float* %3
%45 = load float, float* %4
%46 = load float, float* %5
%47 = call float @rocket_equation(float %44, float %45, float %46)
%48 = fadd float %37, %47
%49 = add nsw i32 %36, -1
%50 = icmp ugt i32 %36, 1
br i1 %50, label %35, label %32
51: ; preds = %10, %30, %32, %17
ret i32 0
}