#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 *, float);
int main(int argc, char *argv[]) {
  float pressure, volume, temp, num_particles;
  float vol_initial = 1.0;
  float vol_final = 2.0;
  float pressure_initial = 1e5;
  int i = 0;
  float work_total = 0;
  float delta_work;
  float delta_vol;
  temp = 300;
  delta_vol = (vol_final - vol_initial) / 2;
  num_particles = pressure_initial * vol_initial / (1.380648813e-23 * temp);
  volume = vol_initial;
  pressure = pressure_initial;
  while (volume <= vol_final) {
    delta_work = pressure * volume;
    work_total += delta_work;
    volume += delta_vol;
    pressure = num_particles * 1.380648813e-23 * temp / volume;
  }
  printf("the total work done by the gas is %f\n", work_total);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movss  0xee6(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  0xecd(%rip),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  0xec8(%rip),%xmm0
movss  %xmm0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
movss  0xea8(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x28(%rbp),%xmm0
subss  -0x24(%rbp),%xmm0
movss  0xe8d(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x2c(%rbp),%xmm0
mulss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x1c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm2
movsd  0xe5d(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x18(%rbp),%xmm1
movss  -0x28(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     1245 <main+0x135>
movss  -0x14(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x38(%rbp),%xmm0
addss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x3c(%rbp),%xmm0
addss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xde7(%rip),%xmm1
mulsd  %xmm1,%xmm0
movss  -0x1c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movss  -0x18(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    11c8 <main+0xb8>
movss  -0x34(%rbp),%xmm0
lea    0xdc7(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeec(%rip),%rdi
movss  0xee0(%rip),%xmm0
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [38 x i8] c"the total work done by the gas is %f\0A\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 float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca i32
%14 = alloca float
%15 = alloca float
%16 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store float 1.000000e+00, float* %10
store float 2.000000e+00, float* %11
store float 1.000000e+05, float* %12
store i32 0, i32* %13
store float 0.000000e+00, float* %14
store float 3.000000e+02, float* %8
%17 = load float, float* %11
%18 = load float, float* %10
%19 = fsub float %17, %18
%20 = fdiv float %19, 2.000000e+00
store float %20, float* %16
%21 = load float, float* %12
%22 = load float, float* %10
%23 = fmul float %21, %22
%24 = fpext float %23 to double
%25 = load float, float* %8
%26 = fpext float %25 to double
%27 = fmul double 0x3B30B0E6AF70CC22, %26
%28 = fdiv double %24, %27
%29 = fptrunc double %28 to float
store float %29, float* %9
%30 = load float, float* %10
store float %30, float* %7
%31 = load float, float* %12
store float %31, float* %6
br label %32
32: ; preds = %36, %2
%33 = load float, float* %7
%34 = load float, float* %11
%35 = fcmp ole float %33, %34
br i1 %35, label %36, label %56
36: ; preds = %32
%37 = load float, float* %6
%38 = load float, float* %7
%39 = fmul float %37, %38
store float %39, float* %15
%40 = load float, float* %15
%41 = load float, float* %14
%42 = fadd float %41, %40
store float %42, float* %14
%43 = load float, float* %16
%44 = load float, float* %7
%45 = fadd float %44, %43
store float %45, float* %7
%46 = load float, float* %9
%47 = fpext float %46 to double
%48 = fmul double %47, 0x3B30B0E6AF70CC22
%49 = load float, float* %8
%50 = fpext float %49 to double
%51 = fmul double %48, %50
%52 = load float, float* %7
%53 = fpext float %52 to double
%54 = fdiv double %51, %53
%55 = fptrunc double %54 to float
store float %55, float* %6
br label %32
56: ; preds = %32
%57 = load float, float* %14
%58 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), float %57)
ret i32 0
}

LLVM IR (-O2):
@.str = [38 x i8] c"the total work done by the gas is %f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), float 3.000000e+05)
ret i32 0
}