#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 */
typedef int loff_t;

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ SEEK_SET;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int lseek64(int, unsigned long long, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int);
scalar_t__ strncmp(char *, char *, int);
int write(int, char *, int);
int write_at_largest_off(int fd, unsigned long long max_off) {
  int ret;
  loff_t lret;
  unsigned long long offset = max_off - (sizeof("Hello World") - 1);
  char buf[(sizeof("Hello World") - 1) + 1];
  memset(buf, 0, (sizeof("Hello World") - 1) + 1);
  lret = lseek64(fd, offset, SEEK_SET);
  if (lret == -1) {
    fprintf(stderr, "Seek error %d: \"%s\"\n", errno, strerror(errno));
    return EINVAL;
  }
  ret = write(fd, "Hello World", (sizeof("Hello World") - 1));
  if (ret == -1) {
    fprintf(stderr, "Write error %d: \"%s\"\n", errno, strerror(errno));
    return EINVAL;
  }
  lret = lseek64(fd, offset, SEEK_SET);
  if (lret == -1) {
    fprintf(stderr, "Seek error %d: \"%s\"\n", errno, strerror(errno));
    return EINVAL;
  }
  ret = read(fd, buf, (sizeof("Hello World") - 1));
  if (ret == -1) {
    fprintf(stderr, "Read error %d: \"%s\"\n", errno, strerror(errno));
    return EINVAL;
  }
  if (strncmp("Hello World", buf, (sizeof("Hello World") - 1)) != 0) {
    fprintf(stderr, "Buffer read back does not match\n");
    fprintf(stderr, "Wrote: %s\n", "Hello World");
    fprintf(stderr, "Read : %s\n", buf);
    return EINVAL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<write_at_largest_off>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    $0xb,%rax
mov    %rax,-0x20(%rbp)
lea    -0x2c(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
call   1080 <lseek64@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    120b <write_at_largest_off+0x9b>
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%edx
mov    %rax,%rcx
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13dd <write_at_largest_off+0x26d>
mov    -0x8(%rbp),%edi
lea    0xe00(%rip),%rsi
mov    $0xb,%edx
call   1040 <write@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    127a <write_at_largest_off+0x10a>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%edx
mov    %rax,%rcx
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13dd <write_at_largest_off+0x26d>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    0x2d48(%rip),%rax
mov    (%rax),%edx
call   1080 <lseek64@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12ea <write_at_largest_off+0x17a>
mov    0x2d3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%edx
mov    %rax,%rcx
lea    0xd2e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2ce8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13dd <write_at_largest_off+0x26d>
mov    -0x8(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0xb,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1356 <write_at_largest_off+0x1e6>
mov    0x2cd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2cbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%edx
mov    %rax,%rcx
lea    0xcf9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13dd <write_at_largest_off+0x26d>
lea    -0x2c(%rbp),%rsi
lea    0xcb4(%rip),%rdi
mov    $0xb,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     13d6 <write_at_largest_off+0x266>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
lea    0xcc7(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
lea    0xcd1(%rip),%rsi
lea    0xc72(%rip),%rdx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c2f(%rip),%rax
mov    (%rax),%edi
lea    -0x2c(%rbp),%rdx
lea    0xcba(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2bfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13dd <write_at_largest_off+0x26d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_at_largest_off>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
add    $0xfffffffffffffff5,%rbx
lea    0x4(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e37(%rip),%r14
mov    (%r14),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <lseek64@plt>
cmp    $0xffffffff,%eax
je     125b <write_at_largest_off+0xeb>
lea    0xe5f(%rip),%rsi
mov    %ebp,%edi
mov    $0xb,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     127d <write_at_largest_off+0x10d>
mov    (%r14),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <lseek64@plt>
cmp    $0xffffffff,%eax
je     125b <write_at_largest_off+0xeb>
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
mov    $0xb,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     129f <write_at_largest_off+0x12f>
lea    0xe17(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    $0xb,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12df <write_at_largest_off+0x16f>
mov    0x2dc3(%rip),%rbx
mov    (%rbx),%edi
lea    0xe26(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe37(%rip),%rsi
lea    0xdd8(%rip),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe2b(%rip),%rsi
lea    0x4(%rsp),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12cd <write_at_largest_off+0x15d>
mov    0x2d7e(%rip),%rax
mov    (%rax),%ebx
mov    0x2d6d(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xd85(%rip),%rsi
jmp    12bf <write_at_largest_off+0x14f>
mov    0x2d5c(%rip),%rax
mov    (%rax),%ebx
mov    0x2d4b(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xd84(%rip),%rsi
jmp    12bf <write_at_largest_off+0x14f>
mov    0x2d3a(%rip),%rax
mov    (%rax),%ebx
mov    0x2d29(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xd78(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2cf4(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
jmp    12d6 <write_at_largest_off+0x166>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"Seek error %d: \22%s\22\0A\00"
@errno = global i32 0
@EINVAL = global i32 0
@.str.1 = [12 x i8] c"Hello World\00"
@.str.2 = [22 x i8] c"Write error %d: \22%s\22\0A\00"
@.str.3 = [21 x i8] c"Read error %d: \22%s\22\0A\00"
@.str.4 = [33 x i8] c"Buffer read back does not match\0A\00"
@.str.5 = [11 x i8] c"Wrote: %s\0A\00"
@.str.6 = [11 x i8] c"Read : %s\0A\00"
define i32 @write_at_largest_off(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca [12 x i8]
store i32 %0, i32* %4
store i64 %1, i64* %5
%10 = load i64, i64* %5
%11 = sub i64 %10, 11
store i64 %11, i64* %8
%12 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 12)
%14 = load i32, i32* %4
%15 = load i64, i64* %8
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @lseek64(i32 %14, i64 %15, i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %27
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %22, i8* %24)
%26 = load i32, i32* @EINVAL
store i32 %26, i32* %3
br label %80
27: ; preds = %2
%28 = load i32, i32* %4
%29 = call i32 @write(i32 %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %39
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %34, i8* %36)
%38 = load i32, i32* @EINVAL
store i32 %38, i32* %3
br label %80
39: ; preds = %27
%40 = load i32, i32* %4
%41 = load i64, i64* %8
%42 = load i32, i32* @SEEK_SET
%43 = call i32 @lseek64(i32 %40, i64 %41, i32 %42)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %53
46: ; preds = %39
%47 = load i32, i32* @stderr
%48 = load i32, i32* @errno
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %48, i8* %50)
%52 = load i32, i32* @EINVAL
store i32 %52, i32* %3
br label %80
53: ; preds = %39
%54 = load i32, i32* %4
%55 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
%56 = call i32 @read(i32 %54, i8* %55, i32 11)
store i32 %56, i32* %6
%57 = load i32, i32* %6
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %66
59: ; preds = %53
%60 = load i32, i32* @stderr
%61 = load i32, i32* @errno
%62 = load i32, i32* @errno
%63 = call i8* @strerror(i32 %62)
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %61, i8* %63)
%65 = load i32, i32* @EINVAL
store i32 %65, i32* %3
br label %80
66: ; preds = %53
%67 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
%68 = call i64 @strncmp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %67, i32 11)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %79
70: ; preds = %66
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%75 = load i32, i32* @stderr
%76 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %76)
%78 = load i32, i32* @EINVAL
store i32 %78, i32* %3
br label %80
79: ; preds = %66
store i32 0, i32* %3
br label %80
80: ; preds = %79, %70, %59, %46, %32, %20
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"Seek error %d: \22%s\22\0A\00"
@errno = global i32 0
@EINVAL = global i32 0
@.str.1 = [12 x i8] c"Hello World\00"
@.str.2 = [22 x i8] c"Write error %d: \22%s\22\0A\00"
@.str.3 = [21 x i8] c"Read error %d: \22%s\22\0A\00"
@.str.4 = [33 x i8] c"Buffer read back does not match\0A\00"
@.str.5 = [11 x i8] c"Wrote: %s\0A\00"
@.str.6 = [11 x i8] c"Read : %s\0A\00"
define i32 @write_at_largest_off(i32 %0, i64 %1) {
%3 = alloca [12 x i8]
%4 = add i64 %1, -11
%5 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 12)
%7 = load i32, i32* @SEEK_SET
%8 = call i32 @lseek64(i32 %0, i64 %4, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %13)
%15 = load i32, i32* @EINVAL
br label %55
16: ; preds = %2
%17 = call i32 @write(i32 %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %21, i8* %22)
%24 = load i32, i32* @EINVAL
br label %55
25: ; preds = %16
%26 = load i32, i32* @SEEK_SET
%27 = call i32 @lseek64(i32 %0, i64 %4, i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %31, i8* %32)
%34 = load i32, i32* @EINVAL
br label %55
35: ; preds = %25
%36 = call i32 @read(i32 %0, i8* %5, i32 11)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %40, i8* %41)
%43 = load i32, i32* @EINVAL
br label %55
44: ; preds = %35
%45 = call i64 @strncmp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %5, i32 11)
%46 = icmp eq i64 %45, 0
br i1 %46, label %55, label %47
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%54 = load i32, i32* @EINVAL
br label %55
55: ; preds = %44, %47, %38, %29, %19, %10
%56 = phi i32 [ %15, %10 ], [ %24, %19 ], [ %34, %29 ], [ %43, %38 ], [ %54, %47 ], [ 0, %44 ]
ret i32 %56
}