#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 */
unsigned char *create_chess_block(long long, int, long long, int);
unsigned char *create_incremental_block(long long, int, long long, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
unsigned char *create_test_block(long long offset, int sector_size,
                                 long long size, int counter, int mode) {
  if (size > 1048576)
    exit(printf("error: requested block (%I64d bytes) is too large\n", size));
  if (!size)
    exit(printf("error: requested a block with size 0 bytes\n"));
  switch (mode) {
  case 0:
    return create_incremental_block(offset, sector_size, size, counter * size);
  case 1:
    return create_chess_block(offset, sector_size, size, counter);
  default:
    printf("Sorry, unsupported mode (-m=%d)\n", mode);
    exit(0);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<create_test_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
cmpq   $0x100000,-0x20(%rbp)
jle    1181 <create_test_block+0x41>
mov    -0x20(%rbp),%rsi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    %eax,%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11a1 <create_test_block+0x61>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    %eax,%edi
call   1060 <exit@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
je     11c5 <create_test_block+0x85>
jmp    11b4 <create_test_block+0x74>
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
je     11e9 <create_test_block+0xa9>
jmp    1205 <create_test_block+0xc5>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
movslq -0x24(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %eax,%ecx
call   1050 <create_incremental_block@plt>
mov    %rax,-0x8(%rbp)
jmp    121d <create_test_block+0xdd>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1030 <create_chess_block@plt>
mov    %rax,-0x8(%rbp)
jmp    121d <create_test_block+0xdd>
mov    -0x28(%rbp),%esi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_test_block>:
push   %rax
cmp    $0x100001,%rdx
jge    1169 <create_test_block+0x29>
test   %rdx,%rdx
je     1181 <create_test_block+0x41>
cmp    $0x1,%r8d
je     1163 <create_test_block+0x23>
test   %r8d,%r8d
jne    1196 <create_test_block+0x56>
imul   %edx,%ecx
pop    %rax
jmp    1050 <create_incremental_block@plt>
pop    %rax
jmp    1030 <create_chess_block@plt>
lea    0xe90(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %eax,%edi
call   1060 <exit@plt>
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %eax,%edi
call   1060 <exit@plt>
lea    0xec2(%rip),%rdi
mov    %r8d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [51 x i8] c"error: requested block (%I64d bytes) is too large\0A\00"
@.str.1 = [44 x i8] c"error: requested a block with size 0 bytes\0A\00"
@.str.2 = [33 x i8] c"Sorry, unsupported mode (-m=%d)\0A\00"
define i8* @create_test_block(i64 %0, i32 %1, i64 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i64 %0, i64* %7
store i32 %1, i32* %8
store i64 %2, i64* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%12 = load i64, i64* %9
%13 = icmp sgt i64 %12, 1048576
br i1 %13, label %14, label %18
14: ; preds = %5
%15 = load i64, i64* %9
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i64 %15)
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %5
%19 = load i64, i64* %9
%20 = icmp ne i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %18
%25 = load i32, i32* %11
switch i32 %25, label %42 [
i32 0, label %26
i32 1, label %36
]
26: ; preds = %24
%27 = load i64, i64* %7
%28 = load i32, i32* %8
%29 = load i64, i64* %9
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = load i64, i64* %9
%33 = mul nsw i64 %31, %32
%34 = trunc i64 %33 to i32
%35 = call i8* @create_incremental_block(i64 %27, i32 %28, i64 %29, i32 %34)
store i8* %35, i8** %6
br label %46
36: ; preds = %24
%37 = load i64, i64* %7
%38 = load i32, i32* %8
%39 = load i64, i64* %9
%40 = load i32, i32* %10
%41 = call i8* @create_chess_block(i64 %37, i32 %38, i64 %39, i32 %40)
store i8* %41, i8** %6
br label %46
42: ; preds = %24
%43 = load i32, i32* %11
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %36, %26
%47 = load i8*, i8** %6
ret i8* %47
}

LLVM IR (-O2):
@.str = [51 x i8] c"error: requested block (%I64d bytes) is too large\0A\00"
@.str.1 = [44 x i8] c"error: requested a block with size 0 bytes\0A\00"
@.str.2 = [33 x i8] c"Sorry, unsupported mode (-m=%d)\0A\00"
define i8* @create_test_block(i64 %0, i32 %1, i64 %2, i32 %3, i32 %4) {
%6 = icmp sgt i64 %2, 1048576
br i1 %6, label %7, label %10
7: ; preds = %5
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i64 %2)
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %5
%11 = icmp eq i64 %2, 0
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %10
switch i32 %4, label %22 [
i32 0, label %16
i32 1, label %20
]
16: ; preds = %15
%17 = trunc i64 %2 to i32
%18 = mul i32 %17, %3
%19 = tail call i8* @create_incremental_block(i64 %0, i32 %1, i64 %2, i32 %18)
br label %25
20: ; preds = %15
%21 = tail call i8* @create_chess_block(i64 %0, i32 %1, i64 %2, i32 %3)
br label %25
22: ; preds = %15
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %4)
%24 = tail call i32 @exit(i32 0)
unreachable
25: ; preds = %20, %16
%26 = phi i8* [ %21, %20 ], [ %19, %16 ]
ret i8* %26
}