#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_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int fd1, fd2;
  fd1 = open("f1", O_RDWR);
  fd2 = open("f1", O_RDWR);
  lseek(fd1, -5, SEEK_END);
  lseek(fd2, 4, SEEK_SET);
  write(fd1, "xyzw", 4);
  write(fd2, "12", 2);
  char buff[10];
  int count;
  lseek(fd1, 0, SEEK_SET);
  while (count = read(fd1, buff, 10))
    write(1, buff, count);
  close(fd1);
  close(fd2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
lea    0xe79(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffb,%esi
call   1040 <lseek@plt>
mov    -0xc(%rbp),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1040 <lseek@plt>
mov    -0x8(%rbp),%edi
lea    0xe3e(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
lea    0xe2f(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
mov    0x2de3(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    -0x8(%rbp),%edi
lea    -0x16(%rbp),%rsi
mov    $0xa,%edx
call   1060 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1229 <main+0xd9>
lea    -0x16(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    11f6 <main+0xa6>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e89(%rip),%r14
mov    (%r14),%esi
lea    0xe97(%rip),%rbp
mov    %rbp,%rdi
call   1070 <open@plt>
mov    %eax,%ebx
mov    (%r14),%esi
mov    %rbp,%rdi
call   1070 <open@plt>
mov    %eax,%r14d
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0xfffffffb,%esi
call   1040 <lseek@plt>
mov    0x2e33(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %r14d,%edi
mov    $0x4,%esi
call   1040 <lseek@plt>
lea    0xe4f(%rip),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
lea    0xe41(%rip),%rsi
mov    %r14d,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    0x0(%rbp),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
lea    0x6(%rsp),%rsi
mov    %ebx,%edi
mov    $0xa,%edx
call   1060 <read@plt>
test   %eax,%eax
je     1222 <main+0xd2>
lea    0x6(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1060 <read@plt>
test   %eax,%eax
jne    1200 <main+0xb0>
mov    %ebx,%edi
call   1050 <close@plt>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"f1\00"
@O_RDWR = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [5 x i8] c"xyzw\00"
@.str.2 = [3 x i8] c"12\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %2
%11 = load i32, i32* @SEEK_END
%12 = call i32 @lseek(i32 %10, i32 -5, i32 %11)
%13 = load i32, i32* %3
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @lseek(i32 %13, i32 4, i32 %14)
%16 = load i32, i32* %2
%17 = call i32 @write(i32 %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%18 = load i32, i32* %3
%19 = call i32 @write(i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%20 = load i32, i32* %2
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @lseek(i32 %20, i32 0, i32 %21)
br label %23
23: ; preds = %28, %0
%24 = load i32, i32* %2
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%26 = call i32 @read(i32 %24, i8* %25, i32 10)
store i32 %26, i32* %5
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%30 = load i32, i32* %5
%31 = call i32 @write(i32 1, i8* %29, i32 %30)
br label %23
32: ; preds = %23
%33 = load i32, i32* %2
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* %3
%36 = call i32 @close(i32 %35)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"f1\00"
@O_RDWR = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [5 x i8] c"xyzw\00"
@.str.2 = [3 x i8] c"12\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @lseek(i32 %3, i32 -5, i32 %6)
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @lseek(i32 %5, i32 4, i32 %8)
%10 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%11 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @lseek(i32 %3, i32 0, i32 %13)
%15 = call i32 @read(i32 %3, i8* %12, i32 10)
%16 = icmp eq i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %0, %17
%18 = phi i32 [ %20, %17 ], [ %15, %0 ]
%19 = call i32 @write(i32 1, i8* %12, i32 %18)
%20 = call i32 @read(i32 %3, i8* %12, i32 10)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %17
22: ; preds = %17, %0
%23 = tail call i32 @close(i32 %3)
%24 = tail call i32 @close(i32 %5)
ret i32 0
}