#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 */
scalar_t__ mode_sense(char *, int *);
scalar_t__ mode_sense10(char *, int *);
scalar_t__ read_capacity(int *, int *);
int get_block_size() {
  char buf[255];
  int len, lba = 0, bsize = 0;
  read_capacity(&lba, &bsize);
  len = 255;
  if (mode_sense(buf, &len) == 0 && buf[3] >= 8) {
    return (((((&buf[4 + 5])[0] << 8) | (&buf[4 + 5])[1]) << 8) |
            (&buf[4 + 5])[2]);
  }
  if (mode_sense10(buf, &len) == 0 &&
      (((&buf[6])[0] << 8) | (&buf[6])[1]) >= 8) {
    return (((((&buf[8 + 5])[0] << 8) | (&buf[8 + 5])[1]) << 8) |
            (&buf[8 + 5])[2]);
  }
  if (read_capacity(&lba, &bsize) == 0) {
    return bsize;
  }
  return -1;
}


x86 assembly (clang, -O0):
<get_block_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x118(%rbp)
movl   $0x0,-0x11c(%rbp)
lea    -0x118(%rbp),%rdi
lea    -0x11c(%rbp),%rsi
call   1030 <read_capacity@plt>
movl   $0xff,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
lea    -0x114(%rbp),%rsi
call   1040 <mode_sense@plt>
cmp    $0x0,%rax
jne    11c0 <get_block_size+0x90>
movsbl -0x10d(%rbp),%eax
cmp    $0x8,%eax
jl     11c0 <get_block_size+0x90>
movsbl -0x107(%rbp),%eax
shl    $0x8,%eax
movsbl -0x106(%rbp),%ecx
or     %ecx,%eax
shl    $0x8,%eax
movsbl -0x105(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1252 <get_block_size+0x122>
lea    -0x110(%rbp),%rdi
lea    -0x114(%rbp),%rsi
call   1050 <mode_sense10@plt>
cmp    $0x0,%rax
jne    1220 <get_block_size+0xf0>
movsbl -0x10a(%rbp),%eax
shl    $0x8,%eax
movsbl -0x109(%rbp),%ecx
or     %ecx,%eax
cmp    $0x8,%eax
jl     1220 <get_block_size+0xf0>
movsbl -0x103(%rbp),%eax
shl    $0x8,%eax
movsbl -0x102(%rbp),%ecx
or     %ecx,%eax
shl    $0x8,%eax
movsbl -0x101(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1252 <get_block_size+0x122>
lea    -0x118(%rbp),%rdi
lea    -0x11c(%rbp),%rsi
call   1030 <read_capacity@plt>
cmp    $0x0,%rax
jne    124b <get_block_size+0x11b>
mov    -0x11c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1252 <get_block_size+0x122>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_block_size>:
sub    $0x118,%rsp
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
call   1030 <read_capacity@plt>
movl   $0xff,0xc(%rsp)
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1040 <mode_sense@plt>
test   %rax,%rax
jne    119a <get_block_size+0x6a>
cmpb   $0x8,0x13(%rsp)
jl     119a <get_block_size+0x6a>
movsbl 0x19(%rsp),%eax
movsbl 0x1a(%rsp),%ecx
shl    $0x10,%eax
shl    $0x8,%ecx
or     %eax,%ecx
movsbl 0x1b(%rsp),%eax
or     %ecx,%eax
add    $0x118,%rsp
ret
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1050 <mode_sense10@plt>
test   %rax,%rax
jne    11db <get_block_size+0xab>
movsbl 0x16(%rsp),%eax
shl    $0x8,%eax
movsbl 0x17(%rsp),%ecx
or     %eax,%ecx
cmp    $0x8,%ecx
jl     11db <get_block_size+0xab>
movsbl 0x1d(%rsp),%eax
movsbl 0x1e(%rsp),%ecx
shl    $0x10,%eax
shl    $0x8,%ecx
or     %eax,%ecx
movsbl 0x1f(%rsp),%eax
jmp    1190 <get_block_size+0x60>
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
call   1030 <read_capacity@plt>
neg    %rax
sbb    %eax,%eax
or     0x4(%rsp),%eax
add    $0x118,%rsp
ret

LLVM IR (-O0):
define i32 @get_block_size() {
%1 = alloca i32
%2 = alloca [255 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call i64 @read_capacity(i32* %4, i32* %5)
store i32 255, i32* %3
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%8 = call i64 @mode_sense(i8* %7, i32* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %32
10: ; preds = %0
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp sge i32 %13, 8
br i1 %14, label %15, label %32
15: ; preds = %10
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 9
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = shl i32 %19, 8
%21 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 9
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = or i32 %20, %24
%26 = shl i32 %25, 8
%27 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 9
%28 = getelementptr inbounds i8, i8* %27, i64 2
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = or i32 %26, %30
store i32 %31, i32* %1
br label %71
32: ; preds = %10, %0
%33 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%34 = call i64 @mode_sense10(i8* %33, i32* %3)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %65
36: ; preds = %32
%37 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 6
%38 = getelementptr inbounds i8, i8* %37, i64 0
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = shl i32 %40, 8
%42 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 6
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = or i32 %41, %45
%47 = icmp sge i32 %46, 8
br i1 %47, label %48, label %65
48: ; preds = %36
%49 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 13
%50 = getelementptr inbounds i8, i8* %49, i64 0
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = shl i32 %52, 8
%54 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 13
%55 = getelementptr inbounds i8, i8* %54, i64 1
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = or i32 %53, %57
%59 = shl i32 %58, 8
%60 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 13
%61 = getelementptr inbounds i8, i8* %60, i64 2
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = or i32 %59, %63
store i32 %64, i32* %1
br label %71
65: ; preds = %36, %32
%66 = call i64 @read_capacity(i32* %4, i32* %5)
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %65
%69 = load i32, i32* %5
store i32 %69, i32* %1
br label %71
70: ; preds = %65
store i32 -1, i32* %1
br label %71
71: ; preds = %70, %68, %48, %15
%72 = load i32, i32* %1
ret i32 %72
}

LLVM IR (-O2):
define i32 @get_block_size() {
%1 = alloca [255 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = call i64 @read_capacity(i32* %3, i32* %4)
store i32 255, i32* %2
%10 = call i64 @mode_sense(i8* %5, i32* %2)
%11 = icmp eq i64 %10, 0
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 3
%13 = load i8, i8* %12
%14 = icmp sgt i8 %13, 7
%15 = select i1 %11, i1 %14, i1 false
br i1 %15, label %16, label %30
16: ; preds = %0
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 9
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 10
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = shl nsw i32 %19, 16
%24 = shl nsw i32 %22, 8
%25 = or i32 %24, %23
%26 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 11
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = or i32 %25, %28
br label %62
30: ; preds = %0
%31 = call i64 @mode_sense10(i8* %5, i32* %2)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %57
33: ; preds = %30
%34 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 6
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = shl nsw i32 %36, 8
%38 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 7
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = or i32 %37, %40
%42 = icmp sgt i32 %41, 7
br i1 %42, label %43, label %57
43: ; preds = %33
%44 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 13
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 14
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = shl nsw i32 %46, 16
%51 = shl nsw i32 %49, 8
%52 = or i32 %51, %50
%53 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 15
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = or i32 %52, %55
br label %62
57: ; preds = %33, %30
%58 = call i64 @read_capacity(i32* %3, i32* %4)
%59 = icmp eq i64 %58, 0
%60 = load i32, i32* %4
%61 = select i1 %59, i32 %60, i32 -1
br label %62
62: ; preds = %57, %43, %16
%63 = phi i32 [ %29, %16 ], [ %56, %43 ], [ %61, %57 ]
ret i32 %63
}