#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*/ O_RDWR;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
int errno;
int /*<<< orphan*/ exit(int);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, struct record *, int);
int write(int, struct record *, int);
int main(int argc, char *argv[]) {
  int fdReadWrite, n;
  int recordSize;
  struct record {
    int id;
    char name[80];
  };
  struct record toModify;
  recordSize = sizeof(struct record);
  if ((fdReadWrite = open("datafile", O_RDWR)) == -1) {
    printf("open error with errno = %d\n", errno);
    perror("datafile");
    exit(1);
  }
  if ((n = lseek(fdReadWrite, recordSize, SEEK_SET)) == -1) {
    printf("lseek error with errno = %d\n", errno);
    perror("datafile");
    exit(1);
  }
  if ((n = read(fdReadWrite, &toModify, recordSize)) == -1) {
    printf("read error with errno = %d\n", errno);
    perror("datafile");
    exit(1);
  }
  printf("About to modify: %d, %s\n", toModify.id, toModify.name);
  toModify.id = 56789;
  if ((n = lseek(fdReadWrite, -1 * recordSize, SEEK_CUR)) == -1) {
    printf("lseek error with errno = %d\n", errno);
    perror("datafile");
    exit(1);
  }
  if ((n = write(fdReadWrite, &toModify, recordSize)) == -1) {
    printf("write error with errno = %d\n", errno);
    perror("datafile");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x54,-0x1c(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    0xe63(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11db <main+0x6b>
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe34(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1228 <main+0xb8>
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde7(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1270 <main+0x100>
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd9f(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x70(%rbp),%esi
lea    -0x70(%rbp),%rdx
add    $0x4,%rdx
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xddd5,-0x70(%rbp)
mov    -0x14(%rbp),%edi
imul   $0xffffffff,-0x1c(%rbp),%esi
mov    0x2d3f(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    12e1 <main+0x171>
mov    0x2d15(%rip),%rax
mov    (%rax),%esi
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd2e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1329 <main+0x1b9>
mov    0x2ccd(%rip),%rax
mov    (%rax),%esi
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xce6(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x60,%rsp
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     122e <main+0xbe>
mov    %eax,%ebx
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x54,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
je     121c <main+0xac>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x54,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0xd0>
mov    0x8(%rsp),%esi
lea    0xc(%rsp),%rdx
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0xddd5,0x8(%rsp)
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0xffffffac,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
je     121c <main+0xac>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x54,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     1252 <main+0xe2>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
ret
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
lea    0xdf9(%rip),%rdi
jmp    1262 <main+0xf2>
mov    0x2d9b(%rip),%rax
mov    (%rax),%esi
lea    0xdcb(%rip),%rdi
jmp    1262 <main+0xf2>
mov    0x2d89(%rip),%rax
mov    (%rax),%esi
lea    0xdf2(%rip),%rdi
jmp    1262 <main+0xf2>
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
lea    0xe15(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd90(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.record = type { i32, [80 x i8] }
%struct.record.0 = type opaque
%struct.record.1 = type opaque
@.str = [9 x i8] c"datafile\00"
@O_RDWR = global i32 0
@.str.1 = [28 x i8] c"open error with errno = %d\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [29 x i8] c"lseek error with errno = %d\0A\00"
@.str.3 = [28 x i8] c"read error with errno = %d\0A\00"
@.str.4 = [25 x i8] c"About to modify: %d, %s\0A\00"
@SEEK_CUR = global i32 0
@.str.5 = [29 x i8] c"write error with errno = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.record
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 84, i32* %8
%10 = load i32, i32* @O_RDWR
%11 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @errno
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i32, i32* %6
%20 = load i32, i32* %8
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @lseek(i32 %19, i32 %20, i32 %21)
store i32 %22, i32* %7
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %29
24: ; preds = %18
%25 = load i32, i32* @errno
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %18
%30 = load i32, i32* %6
%31 = bitcast %struct.record* %9 to %struct.record.0*
%32 = load i32, i32* %8
%33 = call i32 @read(i32 %30, %struct.record.0* %31, i32 %32)
store i32 %33, i32* %7
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %40
35: ; preds = %29
%36 = load i32, i32* @errno
%37 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %29
%41 = getelementptr inbounds %struct.record, %struct.record* %9, i32 0, i32 0
%42 = load i32, i32* %41
%43 = getelementptr inbounds %struct.record, %struct.record* %9, i32 0, i32 1
%44 = getelementptr inbounds [80 x i8], [80 x i8]* %43, i64 0, i64 0
%45 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %42, i8* %44)
%46 = getelementptr inbounds %struct.record, %struct.record* %9, i32 0, i32 0
store i32 56789, i32* %46
%47 = load i32, i32* %6
%48 = load i32, i32* %8
%49 = mul nsw i32 -1, %48
%50 = load i32, i32* @SEEK_CUR
%51 = call i32 @lseek(i32 %47, i32 %49, i32 %50)
store i32 %51, i32* %7
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %58
53: ; preds = %40
%54 = load i32, i32* @errno
%55 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%56 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %40
%59 = load i32, i32* %6
%60 = bitcast %struct.record* %9 to %struct.record.1*
%61 = load i32, i32* %8
%62 = call i32 @write(i32 %59, %struct.record.1* %60, i32 %61)
store i32 %62, i32* %7
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %69
64: ; preds = %58
%65 = load i32, i32* @errno
%66 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %65)
%67 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %58
ret i32 0
}

LLVM IR (-O2):
%struct.record = type { i32, [80 x i8] }
%struct.record.0 = type opaque
%struct.record.1 = type opaque
@.str = [9 x i8] c"datafile\00"
@O_RDWR = global i32 0
@.str.1 = [28 x i8] c"open error with errno = %d\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [29 x i8] c"lseek error with errno = %d\0A\00"
@.str.3 = [28 x i8] c"read error with errno = %d\0A\00"
@.str.4 = [25 x i8] c"About to modify: %d, %s\0A\00"
@SEEK_CUR = global i32 0
@.str.5 = [29 x i8] c"write error with errno = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.record
%4 = bitcast %struct.record* %3 to i8*
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @lseek(i32 %6, i32 84, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i32, i32* @errno
%19 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = bitcast %struct.record* %3 to %struct.record.0*
%24 = call i32 @read(i32 %6, %struct.record.0* %23, i32 84)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i32, i32* @errno
%28 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %22
%32 = getelementptr inbounds %struct.record, %struct.record* %3, i64 0, i32 0
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.record, %struct.record* %3, i64 0, i32 1, i64 0
%35 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %33, i8* %34)
store i32 56789, i32* %32
%36 = load i32, i32* @SEEK_CUR
%37 = call i32 @lseek(i32 %6, i32 -84, i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %44
39: ; preds = %31
%40 = load i32, i32* @errno
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %31
%45 = bitcast %struct.record* %3 to %struct.record.1*
%46 = call i32 @write(i32 %6, %struct.record.1* %45, i32 84)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = load i32, i32* @errno
%50 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %49)
%51 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %44
ret i32 0
}