#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 snprintf(char *, int, char *, long, char const *);
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;
      mul = 1;
      max = 0;
      break;
    }
    if (n > max) {
      warnx("maximum blocksize is %ldG",
            (1024L * 1024L * 1024L) / (1024L * 1024L * 1024L));
      n = max;
    }
    if ((blocksize = n * mul) < 512) {
    underflow:
      warnx("%s: minimum blocksize is 512", p);
      form = "";
      blocksize = n = 512;
    }
  } else
    blocksize = n = 512;
  if (headerlenp)
    *headerlenp = snprintf(header, sizeof(header), "%ld%s-blocks", n, form);
  if (blocksizep)
    *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    0xf03(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe9e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     137d <getbsize+0x23d>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     137d <getbsize+0x23d>
mov    -0x40(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    11aa <getbsize+0x6a>
jmp    134b <getbsize+0x20b>
cmpq   $0x0,-0x18(%rbp)
jne    11bd <getbsize+0x7d>
movq   $0x1,-0x18(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e3 <getbsize+0xa3>
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     11e3 <getbsize+0xa3>
jmp    12da <getbsize+0x19a>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x4c(%rbp)
test   %eax,%eax
je     12c0 <getbsize+0x180>
jmp    11fa <getbsize+0xba>
mov    -0x4c(%rbp),%eax
sub    $0x47,%eax
je     1260 <getbsize+0x120>
jmp    120b <getbsize+0xcb>
mov    -0x4c(%rbp),%eax
sub    $0x4b,%eax
je     1280 <getbsize+0x140>
jmp    121c <getbsize+0xdc>
mov    -0x4c(%rbp),%eax
sub    $0x4d,%eax
je     12a0 <getbsize+0x160>
jmp    122d <getbsize+0xed>
mov    -0x4c(%rbp),%eax
sub    $0x67,%eax
je     1260 <getbsize+0x120>
jmp    123e <getbsize+0xfe>
mov    -0x4c(%rbp),%eax
sub    $0x6b,%eax
je     1280 <getbsize+0x140>
jmp    124f <getbsize+0x10f>
mov    -0x4c(%rbp),%eax
sub    $0x6d,%eax
je     12a0 <getbsize+0x160>
jmp    12d5 <getbsize+0x195>
lea    0xdd5(%rip),%rax
mov    %rax,-0x48(%rbp)
movq   $0x1,-0x20(%rbp)
movq   $0x40000000,-0x28(%rbp)
40
jmp    1304 <getbsize+0x1c4>
lea    0xd83(%rip),%rax
mov    %rax,-0x48(%rbp)
movq   $0x100000,-0x20(%rbp)
movq   $0x400,-0x28(%rbp)
jmp    1304 <getbsize+0x1c4>
lea    0xd65(%rip),%rax
mov    %rax,-0x48(%rbp)
movq   $0x400,-0x20(%rbp)
movq   $0x100000,-0x28(%rbp)
jmp    1304 <getbsize+0x1c4>
movq   $0x40000000,-0x20(%rbp)
40
movq   $0x1,-0x28(%rbp)
jmp    1304 <getbsize+0x1c4>
jmp    12da <getbsize+0x19a>
mov    -0x40(%rbp),%rsi
lea    0xd29(%rip),%rdi
mov    $0x0,%al
call   1040 <warnx@plt>
movq   $0x200,-0x18(%rbp)
movq   $0x1,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jle    132d <getbsize+0x1ed>
lea    0xd0b(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <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    1378 <getbsize+0x238>
jmp    134b <getbsize+0x20b>
mov    -0x40(%rbp),%rsi
lea    0xce8(%rip),%rdi
mov    $0x0,%al
call   1040 <warnx@plt>
lea    0xcf6(%rip),%rax
mov    %rax,-0x48(%rbp)
movq   $0x200,-0x18(%rbp)
movq   $0x200,-0x30(%rbp)
jmp    138d <getbsize+0x24d>
movq   $0x200,-0x18(%rbp)
movq   $0x200,-0x30(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     13c0 <getbsize+0x280>
mov    -0x18(%rbp),%rcx
mov    -0x48(%rbp),%r8
lea    0x2ca9(%rip),%rdi
mov    $0x14,%esi
lea    0xca8(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     13d6 <getbsize+0x296>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    0x2c73(%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    0xea8(%rip),%rdi
call   1030 <getenv@plt>
lea    0xef6(%rip),%rbp
mov    $0x200,%r13d
test   %rax,%rax
je     12ad <getbsize+0x16d>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     12ad <getbsize+0x16d>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1060 <strtol@plt>
test   %rax,%rax
js     1296 <getbsize+0x156>
mov    %rax,%rcx
mov    $0x1,%r13d
cmove  %r13,%rcx
mov    (%rsp),%rdx
movsbl (%rdx),%eax
test   %eax,%eax
je     125b <getbsize+0x11b>
cmpb   $0x0,0x1(%rdx)
je     11df <getbsize+0x9f>
lea    0xe4d(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <warnx@plt>
mov    $0x1,%r13d
lea    0xe80(%rip),%r12
jmp    126c <getbsize+0x12c>
lea    -0x47(%rax),%edx
cmp    $0x26,%edx
ja     1253 <getbsize+0x113>
movabs $0x100000001,%rsi
bt     %rdx,%rsi
jb     122b <getbsize+0xeb>
movabs $0x1000000010,%rsi
bt     %rdx,%rsi
jb     123f <getbsize+0xff>
movabs $0x4000000040,%rsi
bt     %rdx,%rsi
jae    1253 <getbsize+0x113>
lea    0xdee(%rip),%r12
mov    $0x100000,%r13d
mov    $0x400,%ebp
jmp    1267 <getbsize+0x127>
lea    0xe0a(%rip),%r12
mov    $0x40000000,%r13d
mov    $0x1,%ebp
jmp    1267 <getbsize+0x127>
lea    0xdc4(%rip),%r12
mov    $0x400,%r13d
mov    $0x100000,%ebp
jmp    1267 <getbsize+0x127>
test   %eax,%eax
jne    11ba <getbsize+0x7a>
lea    0xdf8(%rip),%r12
mov    $0x40000000,%ebp
cmp    %rbp,%rcx
jbe    1282 <getbsize+0x142>
lea    0xdb1(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <warnx@plt>
mov    %rbp,%rcx
imul   %rcx,%r13
cmp    $0x1ff,%r13
lea    0xdc6(%rip),%rbp
jg     12b5 <getbsize+0x175>
lea    0xda1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <warnx@plt>
mov    $0x200,%r13d
mov    $0x200,%ecx
mov    %rbp,%r12
test   %r15,%r15
je     12d8 <getbsize+0x198>
lea    0x2d8f(%rip),%rdi
lea    0xd93(%rip),%rdx
mov    $0x14,%esi
mov    %r12,%r8
call   1050 <snprintf@plt>
mov    %eax,(%r15)
test   %r14,%r14
je     12e0 <getbsize+0x1a0>
mov    %r13,(%r14)
lea    0x2d69(%rip),%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 = [29 x i8] c"%s: 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 %69
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 %69
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 1, i64* %7
store i64 0, i64* %6
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 %68
64: ; preds = %59
br label %65
65: ; preds = %64, %23
%66 = load i8*, i8** %10
%67 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %66)
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 %68
68: ; preds = %65, %59
br label %70
69: ; preds = %14, %2
store i64 512, i64* %5
store i64 512, i64* %8
br label %70
70: ; preds = %69, %68
%71 = load i32*, i32** %3
%72 = icmp ne i32* %71, null
br i1 %72, label %73, label %78
73: ; preds = %70
%74 = load i64, i64* %5
%75 = load i8*, i8** %11
%76 = 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 %74, i8* %75)
%77 = load i32*, i32** %3
store i32 %76, i32* %77
br label %78
78: ; preds = %73, %70
%79 = load i64*, i64** %4
%80 = icmp ne i64* %79, null
br i1 %80, label %81, label %84
81: ; preds = %78
%82 = load i64, i64* %8
%83 = load i64*, i64** %4
store i64 %82, i64* %83
br label %84
84: ; preds = %81, %78
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 = [29 x i8] c"%s: minimum blocksize is 512\00"
@.str.8 = [13 x i8] c"%ld%s-blocks\00"
define i8* @getbsize(i32* writeonly %0, i64* 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 %48, label %7
7: ; preds = %2
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %48, 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 %46, 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 %35
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 %40
35: ; preds = %28, %30
%36 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %28 ], [ %33, %30 ]
%37 = phi i64 [ 1, %28 ], [ %32, %30 ]
%38 = phi i64 [ 0, %28 ], [ %31, %30 ]
%39 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i64 1)
br label %40
40: ; preds = %35, %30
%41 = phi i8* [ %36, %35 ], [ %33, %30 ]
%42 = phi i64 [ %37, %35 ], [ %32, %30 ]
%43 = phi i64 [ %38, %35 ], [ %15, %30 ]
%44 = mul nsw i64 %43, %42
%45 = icmp slt i64 %44, 512
br i1 %45, label %46, label %48
46: ; preds = %40, %10
%47 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %5)
br label %48
48: ; preds = %2, %7, %40, %46
%49 = phi i64 [ 512, %46 ], [ %44, %40 ], [ 512, %7 ], [ 512, %2 ]
%50 = phi i64 [ 512, %46 ], [ %43, %40 ], [ 512, %7 ], [ 512, %2 ]
%51 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %46 ], [ %41, %40 ], [ 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 ]
%52 = icmp eq i32* %0, null
br i1 %52, label %55, label %53
53: ; preds = %48
%54 = 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 %50, i8* %51)
store i32 %54, i32* %0
br label %55
55: ; preds = %53, %48
%56 = icmp eq i64* %1, null
br i1 %56, label %58, label %57
57: ; preds = %55
store i64 %49, i64* %1
br label %58
58: ; preds = %57, %55
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @getbsize.header, i64 0, i64 0)
}