#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 max_lines(size_t expect_buf_len, size_t actual_buf_len) {
  int expect_lines;
  int actual_lines;
  int max_lines;
  expect_lines = (expect_buf_len + 16 - 1) / 16;
  actual_lines = (actual_buf_len + 16 - 1) / 16;
  if (actual_lines > expect_lines + 4) {
    max_lines = expect_lines + 4;
  } else {
    max_lines = actual_lines;
  }
  return (max_lines < (4096 / 16)) ? max_lines : (4096 / 16);
}


x86 assembly (clang, -O0):
<max_lines>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rax
sub    $0x1,%rax
shr    $0x4,%rax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rax
sub    $0x1,%rax
shr    $0x4,%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x4,%ecx
cmp    %ecx,%eax
jle    1151 <max_lines+0x51>
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x1c(%rbp)
jmp    1157 <max_lines+0x57>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jge    116f <max_lines+0x6f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    117c <max_lines+0x7c>
mov    $0x100,%eax
mov    %eax,-0x20(%rbp)
jmp    117c <max_lines+0x7c>
mov    -0x20(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<max_lines>:
add    $0xf,%rdi
shr    $0x4,%rdi
lea    0xf(%rsi),%rcx
shr    $0x4,%rcx
lea    0x4(%rdi),%eax
cmp    %ecx,%eax
cmovl  %eax,%ecx
cmp    $0x100,%ecx
mov    $0x100,%eax
cmovl  %ecx,%eax
ret

LLVM IR (-O0):
define i32 @max_lines(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i64 %0, i64* %3
store i64 %1, i64* %4
%8 = load i64, i64* %3
%9 = add i64 %8, 16
%10 = sub i64 %9, 1
%11 = udiv i64 %10, 16
%12 = trunc i64 %11 to i32
store i32 %12, i32* %5
%13 = load i64, i64* %4
%14 = add i64 %13, 16
%15 = sub i64 %14, 1
%16 = udiv i64 %15, 16
%17 = trunc i64 %16 to i32
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 4
%21 = icmp sgt i32 %18, %20
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 4
store i32 %24, i32* %7
br label %27
25: ; preds = %2
%26 = load i32, i32* %6
store i32 %26, i32* %7
br label %27
27: ; preds = %25, %22
%28 = load i32, i32* %7
%29 = icmp slt i32 %28, 256
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = load i32, i32* %7
br label %33
32: ; preds = %27
br label %33
33: ; preds = %32, %30
%34 = phi i32 [ %31, %30 ], [ 256, %32 ]
ret i32 %34
}

LLVM IR (-O2):
define i32 @max_lines(i64 %0, i64 %1) {
%3 = add i64 %0, 15
%4 = lshr i64 %3, 4
%5 = trunc i64 %4 to i32
%6 = add i64 %1, 15
%7 = lshr i64 %6, 4
%8 = trunc i64 %7 to i32
%9 = add nsw i32 %5, 4
%10 = icmp slt i32 %9, %8
%11 = select i1 %10, i32 %9, i32 %8
%12 = icmp slt i32 %11, 256
%13 = select i1 %12, i32 %11, i32 256
ret i32 %13
}