#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 /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
scalar_t__ lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
char *strcpy(int /*<<< orphan*/, char *);
char *get_piece(int fd, int piece_num, int piece_len) {
  char buffer[piece_len];
  printf("fuckfuckfuck\n");
  if (lseek(fd, piece_num * piece_len, SEEK_SET) < 0) {
    printf("fuckfuckfuckfuck\n");
    exit(-1);
  }
  if (read(fd, buffer, piece_len) != piece_len) {
    exit(-1);
  }
  printf("%s\n", buffer);
  return strcpy(malloc(sizeof(char) * piece_len), buffer);
}


x86 assembly (clang, -O0):
<get_piece>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
imul   -0xc(%rbp),%esi
mov    0x2e2a(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
cmp    $0x0,%rax
jge    11df <get_piece+0x7f>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rsi
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%edx
call   1060 <read@plt>
cmp    -0xc(%rbp),%eax
je     1201 <get_piece+0xa1>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rsi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_piece>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%r12d
mov    %edi,%r15d
mov    %edx,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe76(%rip),%rdi
call   1040 <puts@plt>
imul   %r14d,%r12d
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    %r12d,%esi
call   1050 <lseek@plt>
test   %rax,%rax
js     11ea <get_piece+0x8a>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <read@plt>
cmp    %r14d,%eax
jne    11f6 <get_piece+0x96>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
call   1070 <malloc@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0f(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"fuckfuckfuck\0A\00"
@SEEK_SET = global i32 0
@.str.1 = [18 x i8] c"fuckfuckfuckfuck\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i8* @get_piece(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %7
%12 = alloca i8, i64 %10
store i64 %10, i64* %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = mul nsw i32 %15, %16
%18 = load i32, i32* @SEEK_SET
%19 = call i64 @lseek(i32 %14, i32 %17, i32 %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %3
%25 = load i32, i32* %4
%26 = load i32, i32* %6
%27 = call i32 @read(i32 %25, i8* %12, i32 %26)
%28 = load i32, i32* %6
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %24
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = mul i64 1, %35
%37 = trunc i64 %36 to i32
%38 = call i32 @malloc(i32 %37)
%39 = call i8* @strcpy(i32 %38, i8* %12)
%40 = load i8*, i8** %7
ret i8* %39
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@str = [13 x i8] c"fuckfuckfuck\00"
@str.3 = [17 x i8] c"fuckfuckfuckfuck\00"
define i8* @get_piece(i32 %0, i32 %1, i32 %2) {
%4 = zext i32 %2 to i64
%5 = alloca i8, i64 %4
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%7 = mul nsw i32 %2, %1
%8 = load i32, i32* @SEEK_SET
%9 = tail call i64 @lseek(i32 %0, i32 %7, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.3, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %3
%15 = call i32 @read(i32 %0, i8* %5, i32 %2)
%16 = icmp eq i32 %15, %2
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %14
%20 = call i32 @puts(i8* %5)
%21 = tail call i32 @malloc(i32 %2)
%22 = call i8* @strcpy(i32 %21, i8* %5)
ret i8* %22
}