#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*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int write(int, int /*<<< orphan*/, int);
void write_piece(int fd, int piece_num, int piece_len, char *buffer) {
  if (lseek(fd, piece_num * piece_len, SEEK_SET) < 0) {
    exit(-1);
    return;
  }
  if (write(fd, strcat(buffer, "\n"), piece_len) != piece_len) {
    printf("Success writing to the file!!!!!\n");
    return;
  }
}


x86 assembly (clang, -O0):
<write_piece>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
imul   -0xc(%rbp),%esi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
cmp    $0x0,%rax
jge    1191 <write_piece+0x41>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
mov    -0xc(%rbp),%edx
call   1030 <write@plt>
cmp    -0xc(%rbp),%eax
je     11c9 <write_piece+0x79>
lea    0xe3c(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_piece>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %edx,%ebx
mov    %edi,%ebp
imul   %edx,%esi
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
test   %rax,%rax
js     11a4 <write_piece+0x54>
lea    0xe88(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcat@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %ebx,%edx
call   1040 <write@plt>
cmp    %ebx,%eax
jne    1194 <write_piece+0x44>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe67(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <puts@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [34 x i8] c"Success writing to the file!!!!!\0A\00"
define void @write_piece(i32 %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = load i32, i32* %7
%12 = mul nsw i32 %10, %11
%13 = load i32, i32* @SEEK_SET
%14 = call i64 @lseek(i32 %9, i32 %12, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %4
%19 = load i32, i32* %5
%20 = load i8*, i8** %8
%21 = call i32 @strcat(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* %7
%23 = call i32 @write(i32 %19, i32 %21, i32 %22)
%24 = load i32, i32* %7
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %18
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [2 x i8] c"\0A\00"
@str = [33 x i8] c"Success writing to the file!!!!!\00"
define void @write_piece(i32 %0, i32 %1, i32 %2, i8* %3) {
%5 = mul nsw i32 %2, %1
%6 = load i32, i32* @SEEK_SET
%7 = tail call i64 @lseek(i32 %0, i32 %5, i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %4
%12 = tail call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @write(i32 %0, i32 %12, i32 %2)
%14 = icmp eq i32 %13, %2
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
ret void
}