#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 *, unsigned short *);
int main() {
  const unsigned short FIRST_CAR_LENGTH = 10, NORMAL_CAR_LENGTH = 8,
                       CAR_CAPACITY = 4;
  unsigned short tracklength = 0, trainlength = FIRST_CAR_LENGTH,
                 maxtrainlength = FIRST_CAR_LENGTH,
                 numpassengers = CAR_CAPACITY, maxnumpassengers = 0,
                 numcars = 1, bestnumcars = 0, numtrains = 1;
  printf("Enter the total length of track in feet:\n> ");
  scanf("%f", &tracklength);
  printf("Enter the maximum length of a train in feet:\n> ");
  scanf("%hd", &maxtrainlength);
  while (trainlength <= maxtrainlength) {
    numtrains = ((float)tracklength / trainlength) * 0.25;
    numpassengers = numcars * CAR_CAPACITY * numtrains;
    if (numpassengers > maxnumpassengers) {
      maxnumpassengers = numpassengers;
      bestnumcars = numcars;
    }
    trainlength += NORMAL_CAR_LENGTH;
    numcars++;
  }
  printf("Your ride can have at most %hd people on it at one time.\n",
         maxnumpassengers);
  printf("This can be achieved with trains of %hd cars.\n", bestnumcars);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movw   $0xa,-0x6(%rbp)
movw   $0x8,-0x8(%rbp)
movw   $0x4,-0xa(%rbp)
movw   $0x0,-0xc(%rbp)
movw   $0xa,-0xe(%rbp)
movw   $0xa,-0x10(%rbp)
movw   $0x4,-0x12(%rbp)
movw   $0x0,-0x14(%rbp)
movw   $0x1,-0x16(%rbp)
movw   $0x0,-0x18(%rbp)
movw   $0x1,-0x1a(%rbp)
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec3(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movzwl -0xe(%rbp),%eax
movzwl -0x10(%rbp),%ecx
cmp    %ecx,%eax
jg     1237 <main+0x117>
movzwl -0xc(%rbp),%eax
cvtsi2ss %eax,%xmm0
movzwl -0xe(%rbp),%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe23(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,-0x1a(%rbp)
movzwl -0x16(%rbp),%eax
shl    $0x2,%eax
movzwl -0x1a(%rbp),%ecx
imul   %ecx,%eax
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%eax
movzwl -0x14(%rbp),%ecx
cmp    %ecx,%eax
jle    121b <main+0xfb>
mov    -0x12(%rbp),%ax
mov    %ax,-0x14(%rbp)
mov    -0x16(%rbp),%ax
mov    %ax,-0x18(%rbp)
movzwl -0xe(%rbp),%eax
add    $0x8,%eax
mov    %ax,-0xe(%rbp)
mov    -0x16(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x16(%rbp)
jmp    11ad <main+0x8d>
movzwl -0x14(%rbp),%esi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzwl -0x18(%rbp),%esi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
movw   $0x0,0x6(%rsp)
movw   $0xa,0x4(%rsp)
lea    0xed0(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeec(%rip),%rdi
lea    0x6(%rsp),%rsi
call   1040 <scanf@plt>
lea    0xede(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf00(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
movzwl 0x4(%rsp),%eax
mov    $0x0,%ebp
cmp    $0xa,%eax
jb     11ef <main+0xcf>
movzwl 0x6(%rsp),%ecx
cvtsi2ss %ecx,%xmm0
mov    $0x1,%cx
mov    $0xa,%esi
mov    $0x4,%di
xor    %edx,%edx
movsd  0xe60(%rip),%xmm1
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorps  %xmm2,%xmm2
cvtsi2ss %esi,%xmm2
movaps %xmm0,%xmm3
divss  %xmm2,%xmm3
xorps  %xmm2,%xmm2
cvtss2sd %xmm3,%xmm2
mulsd  %xmm1,%xmm2
cvttsd2si %xmm2,%ebx
imul   %edi,%ebx
cmp    %bp,%bx
cmova  %ebx,%ebp
cmova  %ecx,%edx
add    $0x8,%esi
add    $0x1,%ecx
movzwl %si,%esi
add    $0x4,%edi
cmp    %eax,%esi
jbe    11b0 <main+0x90>
movzwl %bp,%ebx
movzwl %dx,%ebp
lea    0xe75(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe9f(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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