#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 SEEK_SET;
int /*<<< orphan*/ exit(int);
int ftruncate(int, int /*<<< orphan*/);
scalar_t__ lseek(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
size_t write(int, char *, size_t);
void prepare(int output_fd, char *input, size_t len) {
  if (lseek(output_fd, 0, SEEK_SET == -1)) {
    perror("lseek");
    exit(1);
  }
  if (ftruncate(output_fd, 0) == -1) {
    perror("truncate");
    exit(1);
  }
  if (write(output_fd, input, len) != len) {
    perror("write");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<prepare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e73(%rip),%rax
cmpl   $0xffffffff,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edx
xor    %esi,%esi
call   1050 <lseek@plt>
cmp    $0x0,%rax
je     119f <prepare+0x4f>
lea    0xe70(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1040 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    11c8 <prepare+0x78>
lea    0xe4d(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
cmp    -0x18(%rbp),%rax
je     11f8 <prepare+0xa8>
lea    0xe26(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepare>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e7d(%rip),%rax
xor    %edx,%edx
cmpl   $0xffffffff,(%rax)
sete   %dl
xor    %esi,%esi
call   1050 <lseek@plt>
test   %rax,%rax
jne    119c <prepare+0x4c>
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <ftruncate@plt>
cmp    $0xffffffff,%eax
je     11a5 <prepare+0x55>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <write@plt>
cmp    %rbx,%rax
jne    11ae <prepare+0x5e>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe5d(%rip),%rdi
jmp    11b5 <prepare+0x65>
lea    0xe5a(%rip),%rdi
jmp    11b5 <prepare+0x65>
lea    0xe5a(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [6 x i8] c"lseek\00"
@.str.1 = [9 x i8] c"truncate\00"
@.str.2 = [6 x i8] c"write\00"
define void @prepare(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%7 = load i32, i32* %4
%8 = load i32, i32* @SEEK_SET
%9 = icmp eq i32 %8, -1
%10 = zext i1 %9 to i32
%11 = call i64 @lseek(i32 %7, i32 0, i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %3
%17 = load i32, i32* %4
%18 = call i32 @ftruncate(i32 %17, i32 0)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %16
%24 = load i32, i32* %4
%25 = load i8*, i8** %5
%26 = load i64, i64* %6
%27 = call i64 @write(i32 %24, i8* %25, i64 %26)
%28 = load i64, i64* %6
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %23
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [6 x i8] c"lseek\00"
@.str.1 = [9 x i8] c"truncate\00"
@.str.2 = [6 x i8] c"write\00"
define void @prepare(i32 %0, i8* nocapture %1, i64 %2) {
%4 = load i32, i32* @SEEK_SET
%5 = icmp eq i32 %4, -1
%6 = zext i1 %5 to i32
%7 = tail call i64 @lseek(i32 %0, i32 0, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %3
%13 = tail call i32 @ftruncate(i32 %0, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %12
%19 = tail call i64 @write(i32 %0, i8* %1, i64 %2)
%20 = icmp eq i64 %19, %2
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %18
ret void
}