#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 mc_get_sndbuf(int);
int mc_set_sndbuf(int, int);
void mc_maximize_sndbuf(int sd) {
  int status, min, max, avg;
  min = mc_get_sndbuf(sd);
  if (min < 0) {
    return;
  }
  max = 256 * (1024 * (1024));
  while (min <= max) {
    avg = (min + max) / 2;
    status = mc_set_sndbuf(sd, avg);
    if (status != 0) {
      max = avg - 1;
    } else {
      min = avg + 1;
    }
  }
}


x86 assembly (clang, -O0):
<mc_maximize_sndbuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <mc_get_sndbuf@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1145 <mc_maximize_sndbuf+0x25>
jmp    119d <mc_maximize_sndbuf+0x7d>
movl   $0x10000000,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     119d <mc_maximize_sndbuf+0x7d>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <mc_set_sndbuf@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     118f <mc_maximize_sndbuf+0x6f>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1198 <mc_maximize_sndbuf+0x78>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114c <mc_maximize_sndbuf+0x2c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mc_maximize_sndbuf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
call   1030 <mc_get_sndbuf@plt>
cmp    $0x10000000,%eax
ja     1170 <mc_maximize_sndbuf+0x50>
mov    %eax,%r15d
mov    $0x10000000,%ebx
jmp    114a <mc_maximize_sndbuf+0x2a>
add    $0xffffffff,%ebp
mov    %ebp,%ebx
cmp    %ebx,%r15d
jg     1170 <mc_maximize_sndbuf+0x50>
lea    (%r15,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %r14d,%edi
mov    %ebp,%esi
call   1040 <mc_set_sndbuf@plt>
test   %eax,%eax
jne    1140 <mc_maximize_sndbuf+0x20>
add    $0x1,%ebp
mov    %ebp,%r15d
cmp    %ebx,%r15d
jle    114a <mc_maximize_sndbuf+0x2a>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @mc_maximize_sndbuf(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = call i32 @mc_get_sndbuf(i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
br label %34
12: ; preds = %1
store i32 268435456, i32* %5
br label %13
13: ; preds = %33, %12
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %34
17: ; preds = %13
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = add nsw i32 %18, %19
%21 = sdiv i32 %20, 2
store i32 %21, i32* %6
%22 = load i32, i32* %2
%23 = load i32, i32* %6
%24 = call i32 @mc_set_sndbuf(i32 %22, i32 %23)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %17
%28 = load i32, i32* %6
%29 = sub nsw i32 %28, 1
store i32 %29, i32* %5
br label %33
30: ; preds = %17
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %33
33: ; preds = %30, %27
br label %13
34: ; preds = %11, %13
ret void
}

LLVM IR (-O2):
define void @mc_maximize_sndbuf(i32 %0) {
%2 = tail call i32 @mc_get_sndbuf(i32 %0)
%3 = icmp ugt i32 %2, 268435456
br i1 %3, label %16, label %4
4: ; preds = %1, %4
%5 = phi i32 [ %14, %4 ], [ %2, %1 ]
%6 = phi i32 [ %13, %4 ], [ 268435456, %1 ]
%7 = add nsw i32 %5, %6
%8 = sdiv i32 %7, 2
%9 = tail call i32 @mc_set_sndbuf(i32 %0, i32 %8)
%10 = icmp eq i32 %9, 0
%11 = add nsw i32 %8, -1
%12 = add nsw i32 %8, 1
%13 = select i1 %10, i32 %6, i32 %11
%14 = select i1 %10, i32 %12, i32 %5
%15 = icmp sgt i32 %14, %13
br i1 %15, label %16, label %4
16: ; preds = %4, %1
ret void
}