#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 */
typedef int /*<<< orphan*/ header;

/* Variables and functions */
char *getenv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, long, char const *);
int strlen(char *);
long strtol(char *, char **, int);
int /*<<< orphan*/ warnx(char *, ...);
char *getbsize(int *headerlenp, long *blocksizep) {
  static char header[20];
  long n, max, mul, blocksize;
  char *ep, *p;
  const char *form;
  form = "";
  if ((p = getenv("BLOCKSIZE")) != NULL && *p != '\0') {
    if ((n = strtol(p, &ep, 10)) < 0)
      goto underflow;
    if (n == 0)
      n = 1;
    if (*ep && ep[1])
      goto fmterr;
    switch (*ep) {
    case 'G':
    case 'g':
      form = "G";
      max = (1024L * 1024L * 1024L) / (1024L * 1024L * 1024L);
      mul = (1024L * 1024L * 1024L);
      break;
    case 'K':
    case 'k':
      form = "K";
      max = (1024L * 1024L * 1024L) / (1024L);
      mul = (1024L);
      break;
    case 'M':
    case 'm':
      form = "M";
      max = (1024L * 1024L * 1024L) / (1024L * 1024L);
      mul = (1024L * 1024L);
      break;
    case '\0':
      max = (1024L * 1024L * 1024L);
      mul = 1;
      break;
    default:
    fmterr:
      warnx("%s: unknown blocksize", p);
      n = 512;
      max = (1024L * 1024L * 1024L);
      mul = 1;
      break;
    }
    if (n > max) {
      warnx("maximum blocksize is %ldG",
            (1024L * 1024L * 1024L) / (1024L * 1024L * 1024L));
      n = max;
    }
    if ((blocksize = n * mul) < 512) {
    underflow:
      warnx("minimum blocksize is 512");
      form = "";
      blocksize = n = 512;
    }
  } else
    blocksize = n = 512;
  snprintf(header, sizeof(header), "%ld%s-blocks", n, form);
  *headerlenp = strlen(header);
  *blocksizep = blocksize;
  return (header);
}


x86 assembly (clang, -O0):
<getbsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeef(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe8e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     1389 <getbsize+0x239>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1389 <getbsize+0x239>
mov    -0x40(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    11ba <getbsize+0x6a>
jmp    135b <getbsize+0x20b>
cmpq   $0x0,-0x18(%rbp)
jne    11cd <getbsize+0x7d>
movq   $0x1,-0x18(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f3 <getbsize+0xa3>
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     11f3 <getbsize+0xa3>
jmp    12ea <getbsize+0x19a>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x4c(%rbp)
test   %eax,%eax
je     12d0 <getbsize+0x180>
jmp    120a <getbsize+0xba>
mov    -0x4c(%rbp),%eax
sub    $0x47,%eax
je     1270 <getbsize+0x120>
jmp    121b <getbsize+0xcb>
mov    -0x4c(%rbp),%eax
sub    $0x4b,%eax
je     1290 <getbsize+0x140>
jmp    122c <getbsize+0xdc>
mov    -0x4c(%rbp),%eax
sub    $0x4d,%eax
je     12b0 <getbsize+0x160>
jmp    123d <getbsize+0xed>
mov    -0x4c(%rbp),%eax
sub    $0x67,%eax
je     1270 <getbsize+0x120>
jmp    124e <getbsize+0xfe>
mov    -0x4c(%rbp),%eax
sub    $0x6b,%eax
je     1290 <getbsize+0x140>
jmp    125f <getbsize+0x10f>
mov    -0x4c(%rbp),%eax
sub    $0x6d,%eax
je     12b0 <getbsize+0x160>
jmp    12e5 <getbsize+0x195>
lea    0xdc5(%rip),%rax
mov    %rax,-0x48(%rbp)
movq   $0x1,-0x20(%rbp)
movq   $0x40000000,-0x28(%rbp)
40
jmp    1314 <getbsize+0x1c4>
lea    0xd73(%rip),%rax
mov    %rax,-0x48(%rbp)
movq   $0x100000,-0x20(%rbp)
movq   $0x400,-0x28(%rbp)
jmp    1314 <getbsize+0x1c4>
lea    0xd55(%rip),%rax
mov    %rax,-0x48(%rbp)
movq   $0x400,-0x20(%rbp)
movq   $0x100000,-0x28(%rbp)
jmp    1314 <getbsize+0x1c4>
movq   $0x40000000,-0x20(%rbp)
40
movq   $0x1,-0x28(%rbp)
jmp    1314 <getbsize+0x1c4>
jmp    12ea <getbsize+0x19a>
mov    -0x40(%rbp),%rsi
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1050 <warnx@plt>
movq   $0x200,-0x18(%rbp)
movq   $0x40000000,-0x20(%rbp)
40
movq   $0x1,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jle    133d <getbsize+0x1ed>
lea    0xcfb(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1050 <warnx@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmp    $0x200,%rax
jge    1384 <getbsize+0x234>
jmp    135b <getbsize+0x20b>
lea    0xcdc(%rip),%rdi
mov    $0x0,%al
call   1050 <warnx@plt>
lea    0xce6(%rip),%rax
mov    %rax,-0x48(%rbp)
movq   $0x200,-0x18(%rbp)
movq   $0x200,-0x30(%rbp)
jmp    1399 <getbsize+0x249>
movq   $0x200,-0x18(%rbp)
movq   $0x200,-0x30(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x48(%rbp),%r8
lea    0x2cb8(%rip),%rdi
mov    $0x14,%esi
lea    0xca3(%rip),%rdx
call   1060 <snprintf@plt>
lea    0x2ca0(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    0x2c81(%rip),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbsize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe98(%rip),%rdi
call   1030 <getenv@plt>
lea    0xee2(%rip),%r12
mov    $0x200,%ebp
test   %rax,%rax
je     11e5 <getbsize+0x95>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     11e5 <getbsize+0x95>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1070 <strtol@plt>
test   %rax,%rax
js     12a3 <getbsize+0x153>
mov    $0x1,%ebp
cmove  %rbp,%rax
mov    (%rsp),%rdx
movsbl (%rdx),%ecx
test   %ecx,%ecx
je     126c <getbsize+0x11c>
cmpb   $0x0,0x1(%rdx)
je     11f0 <getbsize+0xa0>
lea    0xe4a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <warnx@plt>
mov    $0x200,%r13d
mov    $0x1,%ebp
lea    0xe76(%rip),%r12
jmp    1296 <getbsize+0x146>
mov    $0x200,%r13d
jmp    12c3 <getbsize+0x173>
lea    -0x47(%rcx),%edx
cmp    $0x26,%edx
ja     1264 <getbsize+0x114>
movabs $0x100000001,%rsi
bt     %rdx,%rsi
jb     123c <getbsize+0xec>
movabs $0x1000000010,%rsi
bt     %rdx,%rsi
jb     1250 <getbsize+0x100>
movabs $0x4000000040,%rsi
bt     %rdx,%rsi
jae    1264 <getbsize+0x114>
lea    0xddd(%rip),%r12
mov    $0x100000,%ebp
mov    $0x400,%r13d
jmp    1279 <getbsize+0x129>
lea    0xdf9(%rip),%r12
mov    $0x40000000,%ebp
mov    $0x1,%r13d
jmp    1279 <getbsize+0x129>
lea    0xdb3(%rip),%r12
mov    $0x400,%ebp
mov    $0x100000,%r13d
jmp    1279 <getbsize+0x129>
test   %ecx,%ecx
jne    11bd <getbsize+0x6d>
lea    0xde3(%rip),%r12
mov    $0x40000000,%r13d
cmp    %r13,%rax
jbe    1293 <getbsize+0x143>
lea    0xd9f(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <warnx@plt>
jmp    1296 <getbsize+0x146>
mov    %rax,%r13
imul   %r13,%rbp
cmp    $0x1ff,%rbp
jg     12c3 <getbsize+0x173>
lea    0xd94(%rip),%rdi
xor    %eax,%eax
call   1050 <warnx@plt>
mov    $0x200,%ebp
mov    $0x200,%r13d
lea    0xd93(%rip),%r12
lea    0x2d96(%rip),%rbx
lea    0xd86(%rip),%rdx
mov    %rbx,%rdi
mov    $0x14,%esi
mov    %r13,%rcx
mov    %r12,%r8
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,(%r15)
mov    %rbp,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@getbsize.header = internal global [20 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
@.str.1 = [10 x i8] c"BLOCKSIZE\00"
@.str.2 = [2 x i8] c"G\00"
@.str.3 = [2 x i8] c"K\00"
@.str.4 = [2 x i8] c"M\00"
@.str.5 = [22 x i8] c"%s: unknown blocksize\00"
@.str.6 = [26 x i8] c"maximum blocksize is %ldG\00"
@.str.7 = [25 x i8] c"minimum blocksize is 512\00"
@.str.8 = [13 x i8] c"%ld%s-blocks\00"
define i8* @getbsize(i32* %0, i64* %1) {
%3 = alloca i32*
%4 = alloca i64*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i32* %0, i32** %3
store i64* %1, i64** %4
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %11
%12 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i8* %12, i8** %10
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %68
14: ; preds = %2
%15 = load i8*, i8** %10
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %68
19: ; preds = %14
%20 = load i8*, i8** %10
%21 = call i64 @strtol(i8* %20, i8** %9, i32 10)
store i64 %21, i64* %5
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
br label %65
24: ; preds = %19
%25 = load i64, i64* %5
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %24
store i64 1, i64* %5
br label %28
28: ; preds = %27, %24
%29 = load i8*, i8** %9
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %28
%34 = load i8*, i8** %9
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %33
br label %49
40: ; preds = %33, %28
%41 = load i8*, i8** %9
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
switch i32 %43, label %48 [
i32 71, label %44
i32 103, label %44
i32 75, label %45
i32 107, label %45
i32 77, label %46
i32 109, label %46
i32 0, label %47
]
44: ; preds = %40, %40
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %11
store i64 1, i64* %6
store i64 1073741824, i64* %7
br label %52
45: ; preds = %40, %40
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %11
store i64 1048576, i64* %6
store i64 1024, i64* %7
br label %52
46: ; preds = %40, %40
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8** %11
store i64 1024, i64* %6
store i64 1048576, i64* %7
br label %52
47: ; preds = %40
store i64 1073741824, i64* %6
store i64 1, i64* %7
br label %52
48: ; preds = %40
br label %49
49: ; preds = %48, %39
%50 = load i8*, i8** %10
%51 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %50)
store i64 512, i64* %5
store i64 1073741824, i64* %6
store i64 1, i64* %7
br label %52
52: ; preds = %49, %47, %46, %45, %44
%53 = load i64, i64* %5
%54 = load i64, i64* %6
%55 = icmp sgt i64 %53, %54
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i64 1)
%58 = load i64, i64* %6
store i64 %58, i64* %5
br label %59
59: ; preds = %56, %52
%60 = load i64, i64* %5
%61 = load i64, i64* %7
%62 = mul nsw i64 %60, %61
store i64 %62, i64* %8
%63 = icmp slt i64 %62, 512
br i1 %63, label %64, label %67
64: ; preds = %59
br label %65
65: ; preds = %64, %23
%66 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %11
store i64 512, i64* %5
store i64 512, i64* %8
br label %67
67: ; preds = %65, %59
br label %69
68: ; preds = %14, %2
store i64 512, i64* %5
store i64 512, i64* %8
br label %69
69: ; preds = %68, %67
%70 = load i64, i64* %5
%71 = load i8*, i8** %11
%72 = call i32 @snprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @getbsize.header, i64 0, i64 0), i32 20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i64 %70, i8* %71)
%73 = call i32 @strlen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @getbsize.header, i64 0, i64 0))
%74 = load i32*, i32** %3
store i32 %73, i32* %74
%75 = load i64, i64* %8
%76 = load i64*, i64** %4
store i64 %75, i64* %76
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @getbsize.header, i64 0, i64 0)
}

LLVM IR (-O2):
@getbsize.header = internal global [20 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
@.str.1 = [10 x i8] c"BLOCKSIZE\00"
@.str.2 = [2 x i8] c"G\00"
@.str.3 = [2 x i8] c"K\00"
@.str.4 = [2 x i8] c"M\00"
@.str.5 = [22 x i8] c"%s: unknown blocksize\00"
@.str.6 = [26 x i8] c"maximum blocksize is %ldG\00"
@.str.7 = [25 x i8] c"minimum blocksize is 512\00"
@.str.8 = [13 x i8] c"%ld%s-blocks\00"
define i8* @getbsize(i32* nocapture writeonly %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %45, label %7
7: ; preds = %2
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %45, label %10
10: ; preds = %7
%11 = call i64 @strtol(i8* %5, i8** %3, i32 10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %43, label %13
13: ; preds = %10
%14 = icmp eq i64 %11, 0
%15 = select i1 %14, i64 1, i64 %11
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %27, label %19
19: ; preds = %13
%20 = getelementptr inbounds i8, i8* %16, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = sext i8 %17 to i32
switch i32 %24, label %28 [
i32 71, label %30
i32 103, label %30
i32 75, label %25
i32 107, label %25
i32 77, label %26
i32 109, label %26
i32 0, label %27
]
25: ; preds = %23, %23
br label %30
26: ; preds = %23, %23
br label %30
27: ; preds = %13, %23
br label %30
28: ; preds = %19, %23
%29 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %5)
br label %37
30: ; preds = %23, %23, %27, %26, %25
%31 = phi i64 [ 1073741824, %27 ], [ 1024, %26 ], [ 1048576, %25 ], [ 1, %23 ], [ 1, %23 ]
%32 = phi i64 [ 1, %27 ], [ 1048576, %26 ], [ 1024, %25 ], [ 1073741824, %23 ], [ 1073741824, %23 ]
%33 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %27 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), %26 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), %25 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %23 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %23 ]
%34 = icmp ugt i64 %15, %31
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i64 1)
br label %37
37: ; preds = %28, %35, %30
%38 = phi i8* [ %33, %35 ], [ %33, %30 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %28 ]
%39 = phi i64 [ %32, %35 ], [ %32, %30 ], [ 1, %28 ]
%40 = phi i64 [ %31, %35 ], [ %15, %30 ], [ 512, %28 ]
%41 = mul nsw i64 %40, %39
%42 = icmp slt i64 %41, 512
br i1 %42, label %43, label %45
43: ; preds = %37, %10
%44 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
br label %45
45: ; preds = %2, %7, %37, %43
%46 = phi i64 [ 512, %43 ], [ %41, %37 ], [ 512, %7 ], [ 512, %2 ]
%47 = phi i64 [ 512, %43 ], [ %40, %37 ], [ 512, %7 ], [ 512, %2 ]
%48 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %43 ], [ %38, %37 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %7 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ]
%49 = tail call i32 @snprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @getbsize.header, i64 0, i64 0), i32 20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i64 %47, i8* %48)
%50 = tail call i32 @strlen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @getbsize.header, i64 0, i64 0))
store i32 %50, i32* %0
store i64 %46, i64* %1
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @getbsize.header, i64 0, i64 0)
}