#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 /*<<< orphan*/ id;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, int *, int);
int /*<<< orphan*/ write(int, ...);
int main() {
  int fd = open("id", O_RDWR | O_CREAT, 0600);
  int id = 10000;
  read(fd, &id, sizeof(id));
  printf("id:%d\n", id++);
  lseek(fd, -4, SEEK_CUR);
  write(fd, &id, sizeof(id));
  lseek(fd, 10, SEEK_END);
  write(fd, "hello", 5);
  lseek(fd, 4, SEEK_SET);
  write(fd, "xxxx", 4);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    0x2e80(%rip),%rax
or     (%rax),%esi
lea    0xe7f(%rip),%rdi
mov    $0x180,%edx
call   1080 <open@plt>
mov    %eax,-0x4(%rbp)
movl   $0x2710,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    -0x8(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffc,%esi
call   1050 <lseek@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
mov    0x2de8(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1050 <lseek@plt>
mov    -0x4(%rbp),%edi
lea    0xe04(%rip),%rsi
mov    $0x5,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
mov    0x2da4(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1050 <lseek@plt>
mov    -0x4(%rbp),%edi
lea    0xdde(%rip),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e75(%rip),%rax
mov    0x2e86(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe83(%rip),%rdi
mov    $0x180,%edx
call   1080 <open@plt>
mov    %eax,%ebx
movl   $0x2710,0x4(%rsp)
lea    0x4(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    0x4(%rsp),%esi
lea    0x1(%rsi),%eax
mov    %eax,0x4(%rsp)
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0xfffffffc,%esi
call   1050 <lseek@plt>
mov    $0x4,%edx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <write@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0xa,%esi
call   1050 <lseek@plt>
lea    0xe0c(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x4,%esi
call   1050 <lseek@plt>
lea    0xde8(%rip),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"id\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [7 x i8] c"id:%d\0A\00"
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@.str.2 = [6 x i8] c"hello\00"
@SEEK_SET = global i32 0
@.str.3 = [5 x i8] c"xxxx\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_CREAT
%5 = or i32 %3, %4
%6 = call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5, i32 384)
store i32 %6, i32* %1
store i32 10000, i32* %2
%7 = load i32, i32* %1
%8 = call i32 @read(i32 %7, i32* %2, i32 4)
%9 = load i32, i32* %2
%10 = add nsw i32 %9, 1
store i32 %10, i32* %2
%11 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%12 = load i32, i32* %1
%13 = load i32, i32* @SEEK_CUR
%14 = call i32 @lseek(i32 %12, i32 -4, i32 %13)
%15 = load i32, i32* %1
%16 = call i32 (i32, ...) @write(i32 %15, i32* %2, i64 4)
%17 = load i32, i32* %1
%18 = load i32, i32* @SEEK_END
%19 = call i32 @lseek(i32 %17, i32 10, i32 %18)
%20 = load i32, i32* %1
%21 = call i32 (i32, ...) @write(i32 %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%22 = load i32, i32* %1
%23 = load i32, i32* @SEEK_SET
%24 = call i32 @lseek(i32 %22, i32 4, i32 %23)
%25 = load i32, i32* %1
%26 = call i32 (i32, ...) @write(i32 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%27 = load i32, i32* %1
%28 = call i32 @close(i32 %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"id\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [7 x i8] c"id:%d\0A\00"
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@.str.2 = [6 x i8] c"hello\00"
@SEEK_SET = global i32 0
@.str.3 = [5 x i8] c"xxxx\00"
define i32 @main() {
%1 = alloca i32
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %4, i32 384)
%6 = bitcast i32* %1 to i8*
store i32 10000, i32* %1
%7 = call i32 @read(i32 %5, i32* %1, i32 4)
%8 = load i32, i32* %1
%9 = add nsw i32 %8, 1
store i32 %9, i32* %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%11 = load i32, i32* @SEEK_CUR
%12 = tail call i32 @lseek(i32 %5, i32 -4, i32 %11)
%13 = call i32 (i32, ...) @write(i32 %5, i32* %1, i64 4)
%14 = load i32, i32* @SEEK_END
%15 = call i32 @lseek(i32 %5, i32 10, i32 %14)
%16 = call i32 (i32, ...) @write(i32 %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @lseek(i32 %5, i32 4, i32 %17)
%19 = call i32 (i32, ...) @write(i32 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%20 = call i32 @close(i32 %5)
ret i32 0
}