#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void rollerCoaster(int trackLength, int maxTrainLength, int *pMaxPeople,
                   int *pNumCars) {
  const unsigned short NORMAL_CAR_LENGTH = 8, CAR_CAPACITY = 4;
  unsigned short trainlength = maxTrainLength, numpassengers = CAR_CAPACITY,
                 numcars = 1, numtrains = 1;
  printf("Enter the maximum length of a train in feet:\n> ");
  scanf("%d", &maxTrainLength);
  while (trainlength <= maxTrainLength) {
    numtrains = ((float)trackLength / trainlength) * 0.25;
    numpassengers = numcars * CAR_CAPACITY * numtrains;
    if (numpassengers > *pMaxPeople) {
      *pMaxPeople = numpassengers;
      *pNumCars = numcars;
    }
    trainlength += NORMAL_CAR_LENGTH;
    numcars++;
  }
  printf("Your ride can have at most %d people on it at one time.\n",
         *pMaxPeople);
  printf("This can be achieved with trains of %d cars.\n", *pNumCars);
}


x86 assembly (clang, -O0):
<rollerCoaster>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movw   $0x8,-0x1a(%rbp)
movw   $0x4,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    %ax,-0x1e(%rbp)
movw   $0x4,-0x20(%rbp)
movw   $0x1,-0x22(%rbp)
movw   $0x1,-0x24(%rbp)
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movzwl -0x1e(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1201 <rollerCoaster+0xe1>
cvtsi2ssl -0x4(%rbp),%xmm0
movzwl -0x1e(%rbp),%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe5d(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,-0x24(%rbp)
movzwl -0x22(%rbp),%eax
shl    $0x2,%eax
movzwl -0x24(%rbp),%ecx
imul   %ecx,%eax
mov    %ax,-0x20(%rbp)
movzwl -0x20(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jle    11e5 <rollerCoaster+0xc5>
movzwl -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movzwl -0x22(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movzwl -0x1e(%rbp),%eax
add    $0x8,%eax
mov    %ax,-0x1e(%rbp)
mov    -0x22(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x22(%rbp)
jmp    1179 <rollerCoaster+0x59>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rollerCoaster>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %edi,%r15d
mov    %esi,0x4(%rsp)
lea    0xecb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeed(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
movzwl %bp,%ecx
cmp    %eax,%ecx
jle    118c <rollerCoaster+0x6c>
mov    (%rbx),%esi
lea    0xed2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r14),%esi
lea    0xefa(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
cvtsi2ss %r15d,%xmm0
mov    $0x1,%dx
mov    $0x4,%si
movsd  0xe5f(%rip),%xmm1
jmp    11c0 <rollerCoaster+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x8,%ecx
add    $0x1,%edx
movzwl %cx,%ecx
add    $0x4,%esi
cmp    %eax,%ecx
jg     1160 <rollerCoaster+0x40>
xorps  %xmm2,%xmm2
cvtsi2ss %ecx,%xmm2
movaps %xmm0,%xmm3
divss  %xmm2,%xmm3
xorps  %xmm2,%xmm2
cvtss2sd %xmm3,%xmm2
mulsd  %xmm1,%xmm2
cvttsd2si %xmm2,%edi
imul   %esi,%edi
movzwl %di,%edi
cmp    %edi,(%rbx)
jge    11b0 <rollerCoaster+0x90>
movzwl %dx,%ebp
mov    %edi,(%rbx)
mov    %ebp,(%r14)
jmp    11b0 <rollerCoaster+0x90>

LLVM IR (-O0):
@.str = [48 x i8] c"Enter the maximum length of a train in feet:\0A> \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [57 x i8] c"Your ride can have at most %d people on it at one time.\0A\00"
@.str.3 = [46 x i8] c"This can be achieved with trains of %d cars.\0A\00"
define void @rollerCoaster(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i16
%10 = alloca i16
%11 = alloca i16
%12 = alloca i16
%13 = alloca i16
%14 = alloca i16
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i16 8, i16* %9
store i16 4, i16* %10
%15 = load i32, i32* %6
%16 = trunc i32 %15 to i16
store i16 %16, i16* %11
store i16 4, i16* %12
store i16 1, i16* %13
store i16 1, i16* %14
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
br label %19
19: ; preds = %53, %4
%20 = load i16, i16* %11
%21 = zext i16 %20 to i32
%22 = load i32, i32* %6
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %60
24: ; preds = %19
%25 = load i32, i32* %5
%26 = sitofp i32 %25 to float
%27 = load i16, i16* %11
%28 = zext i16 %27 to i32
%29 = sitofp i32 %28 to float
%30 = fdiv float %26, %29
%31 = fpext float %30 to double
%32 = fmul double %31, 2.500000e-01
%33 = fptoui double %32 to i16
store i16 %33, i16* %14
%34 = load i16, i16* %13
%35 = zext i16 %34 to i32
%36 = mul nsw i32 %35, 4
%37 = load i16, i16* %14
%38 = zext i16 %37 to i32
%39 = mul nsw i32 %36, %38
%40 = trunc i32 %39 to i16
store i16 %40, i16* %12
%41 = load i16, i16* %12
%42 = zext i16 %41 to i32
%43 = load i32*, i32** %7
%44 = load i32, i32* %43
%45 = icmp sgt i32 %42, %44
br i1 %45, label %46, label %53
46: ; preds = %24
%47 = load i16, i16* %12
%48 = zext i16 %47 to i32
%49 = load i32*, i32** %7
store i32 %48, i32* %49
%50 = load i16, i16* %13
%51 = zext i16 %50 to i32
%52 = load i32*, i32** %8
store i32 %51, i32* %52
br label %53
53: ; preds = %46, %24
%54 = load i16, i16* %11
%55 = zext i16 %54 to i32
%56 = add nsw i32 %55, 8
%57 = trunc i32 %56 to i16
store i16 %57, i16* %11
%58 = load i16, i16* %13
%59 = add i16 %58, 1
store i16 %59, i16* %13
br label %19
60: ; preds = %19
%61 = load i32*, i32** %7
%62 = load i32, i32* %61
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i32 %62)
%64 = load i32*, i32** %8
%65 = load i32, i32* %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %65)
ret void
}

LLVM IR (-O2):
@.str = [48 x i8] c"Enter the maximum length of a train in feet:\0A> \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [57 x i8] c"Your ride can have at most %d people on it at one time.\0A\00"
@.str.3 = [46 x i8] c"This can be achieved with trains of %d cars.\0A\00"
define void @rollerCoaster(i32 %0, i32 %1, i32* nocapture %2, i32* nocapture %3) {
%5 = alloca i32
store i32 %1, i32* %5
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 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* %5)
%8 = load i32, i32* %5
%9 = and i32 %1, 65535
%10 = icmp sgt i32 %9, %8
br i1 %10, label %33, label %11
11: ; preds = %4
%12 = sitofp i32 %0 to float
br label %13
13: ; preds = %11, %28
%14 = phi i32 [ %9, %11 ], [ %31, %28 ]
%15 = phi i16 [ 1, %11 ], [ %30, %28 ]
%16 = sitofp i32 %14 to float
%17 = fdiv float %12, %16
%18 = fpext float %17 to double
%19 = fmul double %18, 2.500000e-01
%20 = fptoui double %19 to i16
%21 = shl i16 %15, 2
%22 = mul i16 %21, %20
%23 = zext i16 %22 to i32
%24 = load i32, i32* %2
%25 = icmp slt i32 %24, %23
br i1 %25, label %26, label %28
26: ; preds = %13
%27 = zext i16 %15 to i32
store i32 %23, i32* %2
store i32 %27, i32* %3
br label %28
28: ; preds = %26, %13
%29 = add nuw nsw i32 %14, 8
%30 = add i16 %15, 1
%31 = and i32 %29, 65535
%32 = icmp sgt i32 %31, %8
br i1 %32, label %33, label %13
33: ; preds = %28, %4
%34 = load i32, i32* %2
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %3
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %36)
ret void
}