#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 *, char *);
int read(int, char *, int);
char *strcpy(int /*<<< orphan*/, char *);
char *get_piece_from_file(int fd, int piece_num, int piece_len) {
  char buffer[piece_len];
  if (lseek(fd, piece_num * piece_len, SEEK_SET) < 0) {
    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_from_file>:
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)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
imul   -0xc(%rbp),%esi
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
cmp    $0x0,%rax
jge    11c3 <get_piece_from_file+0x63>
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     11e5 <get_piece_from_file+0x85>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rsi
lea    0xe10(%rip),%rdi
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_from_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %edi,%r15d
mov    %edx,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
imul   %edx,%esi
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
test   %rax,%rax
js     11d8 <get_piece_from_file+0x78>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <read@plt>
cmp    %r14d,%eax
jne    11d8 <get_piece_from_file+0x78>
lea    0xe4d(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r14d,%edi
call   1070 <malloc@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i8* @get_piece_from_file(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 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = mul nsw i32 %14, %15
%17 = load i32, i32* @SEEK_SET
%18 = call i64 @lseek(i32 %13, i32 %16, i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %3
%23 = load i32, i32* %4
%24 = load i32, i32* %6
%25 = call i32 @read(i32 %23, i8* %12, i32 %24)
%26 = load i32, i32* %6
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %22
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %12)
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = mul i64 1, %33
%35 = trunc i64 %34 to i32
%36 = call i32 @malloc(i32 %35)
%37 = call i8* @strcpy(i32 %36, i8* %12)
%38 = load i8*, i8** %7
ret i8* %37
}

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