#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*/ fflush(int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdout;
int Pa_GetMinNumBuffers(int framesPerBuffer, double framesPerSecond) {
  int minBuffers;
  int minLatencyMsec = (100);
  char *minLatencyText = getenv(("PA_MIN_LATENCY_MSEC"));
  if (minLatencyText != NULL) {
    {
      printf("PA_MIN_LATENCY_MSEC = %s\n", minLatencyText);
      fflush(stdout);
    };
    minLatencyMsec = atoi(minLatencyText);
    if (minLatencyMsec < 1)
      minLatencyMsec = 1;
    else if (minLatencyMsec > 5000)
      minLatencyMsec = 5000;
  }
  minBuffers =
      (int)((minLatencyMsec * framesPerSecond) / (1000.0 * framesPerBuffer));
  if (minBuffers < 2)
    minBuffers = 2;
  return minBuffers;
}


x86 assembly (clang, -O0):
<Pa_GetMinNumBuffers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movl   $0x64,-0x18(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d0 <Pa_GetMinNumBuffers+0x90>
mov    -0x20(%rbp),%rsi
lea    0xe9f(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jge    11b2 <Pa_GetMinNumBuffers+0x72>
movl   $0x1,-0x18(%rbp)
jmp    11cb <Pa_GetMinNumBuffers+0x8b>
cmpl   $0x1388,-0x18(%rbp)
jle    11c6 <Pa_GetMinNumBuffers+0x86>
movl   $0x1388,-0x18(%rbp)
jmp    11cb <Pa_GetMinNumBuffers+0x8b>
jmp    11d0 <Pa_GetMinNumBuffers+0x90>
cvtsi2sdl -0x18(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm2
movsd  0xe19(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    1207 <Pa_GetMinNumBuffers+0xc7>
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Pa_GetMinNumBuffers>:
push   %rbp
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
mov    %edi,%ebp
lea    0xec7(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     119d <Pa_GetMinNumBuffers+0x5d>
mov    %rax,%rbx
lea    0xec7(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    %rbx,%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    11a7 <Pa_GetMinNumBuffers+0x67>
cmp    $0x1388,%eax
mov    $0x1388,%ecx
cmovb  %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
jmp    11af <Pa_GetMinNumBuffers+0x6f>
movsd  0xe5b(%rip),%xmm0
jmp    11af <Pa_GetMinNumBuffers+0x6f>
movsd  0xe59(%rip),%xmm0
movsd  (%rsp),%xmm2
cvtsi2sd %ebp,%xmm1
mulsd  0xe50(%rip),%xmm1
mulsd  %xmm2,%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
cmp    $0x3,%ecx
mov    $0x2,%eax
cmovge %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"PA_MIN_LATENCY_MSEC\00"
@.str.1 = [26 x i8] c"PA_MIN_LATENCY_MSEC = %s\0A\00"
@stdout = global i32 0
define i32 @Pa_GetMinNumBuffers(i32 %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %3
store double %1, double* %4
store i32 100, i32* %6
%8 = call i8* @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %7
%9 = load i8*, i8** %7
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %27
11: ; preds = %2
%12 = load i8*, i8** %7
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @stdout
%15 = call i32 @fflush(i32 %14)
%16 = load i8*, i8** %7
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %11
store i32 1, i32* %6
br label %26
21: ; preds = %11
%22 = load i32, i32* %6
%23 = icmp sgt i32 %22, 5000
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 5000, i32* %6
br label %25
25: ; preds = %24, %21
br label %26
26: ; preds = %25, %20
br label %27
27: ; preds = %26, %2
%28 = load i32, i32* %6
%29 = sitofp i32 %28 to double
%30 = load double, double* %4
%31 = fmul double %29, %30
%32 = load i32, i32* %3
%33 = sitofp i32 %32 to double
%34 = fmul double 1.000000e+03, %33
%35 = fdiv double %31, %34
%36 = fptosi double %35 to i32
store i32 %36, i32* %5
%37 = load i32, i32* %5
%38 = icmp slt i32 %37, 2
br i1 %38, label %39, label %40
39: ; preds = %27
store i32 2, i32* %5
br label %40
40: ; preds = %39, %27
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
@.str = [20 x i8] c"PA_MIN_LATENCY_MSEC\00"
@.str.1 = [26 x i8] c"PA_MIN_LATENCY_MSEC = %s\0A\00"
@stdout = global i32 0
define i32 @Pa_GetMinNumBuffers(i32 %0, double %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = load i32, i32* @stdout
%8 = tail call i32 @fflush(i32 %7)
%9 = tail call i32 @atoi(i8* %3)
%10 = icmp slt i32 %9, 1
br i1 %10, label %15, label %11
11: ; preds = %5
%12 = icmp ult i32 %9, 5000
%13 = select i1 %12, i32 %9, i32 5000
%14 = sitofp i32 %13 to double
br label %15
15: ; preds = %5, %11, %2
%16 = phi double [ %14, %11 ], [ 1.000000e+02, %2 ], [ 1.000000e+00, %5 ]
%17 = fmul double %16, %1
%18 = sitofp i32 %0 to double
%19 = fmul double %18, 1.000000e+03
%20 = fdiv double %17, %19
%21 = fptosi double %20 to i32
%22 = icmp sgt i32 %21, 2
%23 = select i1 %22, i32 %21, i32 2
ret i32 %23
}