#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 ssize_t;
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ line;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ getpid();
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, long, long);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, long);
int /*<<< orphan*/ sscanf(char *, char *, long *);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  pid_t pid;
  int fd, i;
  char line[(10) + 1];
  ssize_t n;
  long seqno;
  pid = getpid();
  if ((fd = open("testfile", O_RDWR)) == -1) {
    do {
      errno = errno;
      perror("open");
      exit(EXIT_FAILURE);
    } while (0);
  }
  for (i = 0; i < (10); ++i) {
    if (lseek(fd, 0, SEEK_SET) == -1) {
      do {
        errno = errno;
        perror("lseek");
        exit(EXIT_FAILURE);
      } while (0);
    }
    if ((n = read(fd, line, (10))) == -1) {
      do {
        errno = errno;
        perror("read");
        exit(EXIT_FAILURE);
      } while (0);
    }
    line[n] = '\0';
    sscanf(line, "%ld\n", &seqno);
    printf("%s: pid = %ld, seq = %ld\n", argv[0], (long)pid, seqno);
    ++seqno;
    snprintf(line, sizeof(line), "%ld\n", seqno);
    if (lseek(fd, 0, SEEK_SET) == -1) {
      do {
        errno = errno;
        perror("lseek");
        exit(EXIT_FAILURE);
      } while (0);
    }
    if (write(fd, line, strlen(line)) == -1) {
      do {
        errno = errno;
        perror("write");
        exit(EXIT_FAILURE);
      } while (0);
    }
  }
  if (close(fd) == -1) {
    do {
      errno = errno;
      perror("close");
      exit(EXIT_FAILURE);
    } while (0);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
lea    0xe0f(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1233 <main+0x73>
jmp    1207 <main+0x47>
mov    0x2dca(%rip),%rax
mov    (%rax),%ecx
mov    0x2dc1(%rip),%rax
mov    %ecx,(%rax)
lea    0xde9(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0xa,-0x20(%rbp)
jge    13fb <main+0x23b>
mov    -0x1c(%rbp),%edi
mov    0x2d82(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1291 <main+0xd1>
jmp    1265 <main+0xa5>
mov    0x2d6c(%rip),%rax
mov    (%rax),%ecx
mov    0x2d63(%rip),%rax
mov    %ecx,(%rax)
lea    0xd90(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x1c(%rbp),%edi
lea    -0x2b(%rbp),%rsi
mov    $0xa,%edx
call   10a0 <read@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    12df <main+0x11f>
jmp    12b3 <main+0xf3>
mov    0x2d1e(%rip),%rax
mov    (%rax),%ecx
mov    0x2d15(%rip),%rax
mov    %ecx,(%rax)
lea    0xd48(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
movslq -0x30(%rbp),%rax
movb   $0x0,-0x2b(%rbp,%rax,1)
lea    -0x2b(%rbp),%rdi
lea    0xd3b(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   10b0 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xd07(%rip),%rdi
call   1060 <printf@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
lea    -0x2b(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    $0xb,%esi
lea    0xcf7(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x1c(%rbp),%edi
mov    0x2c8a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1389 <main+0x1c9>
jmp    135d <main+0x19d>
mov    0x2c74(%rip),%rax
mov    (%rax),%ecx
mov    0x2c6b(%rip),%rax
mov    %ecx,(%rax)
lea    0xc98(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c46(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x44(%rbp)
lea    -0x2b(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x2b(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    13e8 <main+0x228>
jmp    13bc <main+0x1fc>
mov    0x2c15(%rip),%rax
mov    (%rax),%ecx
mov    0x2c0c(%rip),%rax
mov    %ecx,(%rax)
lea    0xc5e(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2be7(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    13ed <main+0x22d>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    123a <main+0x7a>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
cmp    $0xffffffff,%eax
jne    143d <main+0x27d>
jmp    1411 <main+0x251>
mov    0x2bc0(%rip),%rax
mov    (%rax),%ecx
mov    0x2bb7(%rip),%rax
mov    %ecx,(%rax)
lea    0xc0f(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2b92(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    0x2b7c(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x10(%rsp)
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%r15
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
lea    0xe13(%rip),%rdi
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
jne    1203 <main+0x43>
lea    0xe0b(%rip),%rdi
jmp    1300 <main+0x140>
mov    %eax,%ebp
mov    $0xa,%r13d
mov    0x2dc6(%rip),%r14
lea    0x1d(%rsp),%rbx
lea    0xe10(%rip),%r12
xchg   %ax,%ax
mov    (%r14),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1080 <lseek@plt>
cmp    $0xffffffff,%eax
je     12e7 <main+0x127>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
call   10a0 <read@plt>
cmp    $0xffffffff,%eax
je     12f0 <main+0x130>
cltq
movb   $0x0,0x1d(%rsp,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
lea    0x8(%rsp),%rdx
call   10b0 <sscanf@plt>
mov    0x10(%rsp),%rax
mov    (%rax),%rsi
mov    0x8(%rsp),%rcx
lea    0xda1(%rip),%rdi
mov    %r15,%rdx
call   1060 <printf@plt>
mov    0x8(%rsp),%rcx
add    $0x1,%rcx
mov    %rcx,0x8(%rsp)
mov    %rbx,%rdi
mov    $0xb,%esi
mov    %r12,%rdx
call   1070 <snprintf@plt>
mov    (%r14),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1080 <lseek@plt>
cmp    $0xffffffff,%eax
je     12e7 <main+0x127>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     12f9 <main+0x139>
add    $0xffffffff,%r13d
jne    1220 <main+0x60>
mov    %ebp,%edi
call   1090 <close@plt>
cmp    $0xffffffff,%eax
jne    1313 <main+0x153>
lea    0xd54(%rip),%rdi
jmp    1300 <main+0x140>
lea    0xd20(%rip),%rdi
jmp    1300 <main+0x140>
lea    0xd1d(%rip),%rdi
jmp    1300 <main+0x140>
lea    0xd33(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"testfile\00"
@O_RDWR = global i32 0
@errno = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [6 x i8] c"lseek\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [5 x i8] c"%ld\0A\00"
@.str.5 = [26 x i8] c"%s: pid = %ld, seq = %ld\0A\00"
@.str.6 = [6 x i8] c"write\00"
@.str.7 = [6 x i8] c"close\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca [11 x i8]
%10 = alloca i32
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i64 (...) @getpid()
store i64 %12, i64* %6
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %7
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %23
16: ; preds = %2
br label %17
17: ; preds = %16
%18 = load i32, i32* @errno
store i32 %18, i32* @errno
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; No predecessors!
br label %23
23: ; preds = %22, %2
store i32 0, i32* %8
br label %24
24: ; preds = %94, %23
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 10
br i1 %26, label %27, label %97
27: ; preds = %24
%28 = load i32, i32* %7
%29 = load i32, i32* @SEEK_SET
%30 = call i32 @lseek(i32 %28, i32 0, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %39
32: ; preds = %27
br label %33
33: ; preds = %32
%34 = load i32, i32* @errno
store i32 %34, i32* @errno
%35 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; No predecessors!
br label %39
39: ; preds = %38, %27
%40 = load i32, i32* %7
%41 = getelementptr inbounds [11 x i8], [11 x i8]* %9, i64 0, i64 0
%42 = call i32 @read(i32 %40, i8* %41, i32 10)
store i32 %42, i32* %10
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %51
44: ; preds = %39
br label %45
45: ; preds = %44
%46 = load i32, i32* @errno
store i32 %46, i32* @errno
%47 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; No predecessors!
br label %51
51: ; preds = %50, %39
%52 = load i32, i32* %10
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [11 x i8], [11 x i8]* %9, i64 0, i64 %53
store i8 0, i8* %54
%55 = getelementptr inbounds [11 x i8], [11 x i8]* %9, i64 0, i64 0
%56 = call i32 @sscanf(i8* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64* %11)
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 0
%59 = load i8*, i8** %58
%60 = load i64, i64* %6
%61 = load i64, i64* %11
%62 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %59, i64 %60, i64 %61)
%63 = load i64, i64* %11
%64 = add nsw i64 %63, 1
store i64 %64, i64* %11
%65 = getelementptr inbounds [11 x i8], [11 x i8]* %9, i64 0, i64 0
%66 = load i64, i64* %11
%67 = call i32 @snprintf(i8* %65, i32 11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %66)
%68 = load i32, i32* %7
%69 = load i32, i32* @SEEK_SET
%70 = call i32 @lseek(i32 %68, i32 0, i32 %69)
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %79
72: ; preds = %51
br label %73
73: ; preds = %72
%74 = load i32, i32* @errno
store i32 %74, i32* @errno
%75 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%76 = load i32, i32* @EXIT_FAILURE
%77 = call i32 @exit(i32 %76)
unreachable
78: ; No predecessors!
br label %79
79: ; preds = %78, %51
%80 = load i32, i32* %7
%81 = getelementptr inbounds [11 x i8], [11 x i8]* %9, i64 0, i64 0
%82 = getelementptr inbounds [11 x i8], [11 x i8]* %9, i64 0, i64 0
%83 = call i32 @strlen(i8* %82)
%84 = call i32 @write(i32 %80, i8* %81, i32 %83)
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %93
86: ; preds = %79
br label %87
87: ; preds = %86
%88 = load i32, i32* @errno
store i32 %88, i32* @errno
%89 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%90 = load i32, i32* @EXIT_FAILURE
%91 = call i32 @exit(i32 %90)
unreachable
92: ; No predecessors!
br label %93
93: ; preds = %92, %79
br label %94
94: ; preds = %93
%95 = load i32, i32* %8
%96 = add nsw i32 %95, 1
store i32 %96, i32* %8
br label %24
97: ; preds = %24
%98 = load i32, i32* %7
%99 = call i32 @close(i32 %98)
%100 = icmp eq i32 %99, -1
br i1 %100, label %101, label %108
101: ; preds = %97
br label %102
102: ; preds = %101
%103 = load i32, i32* @errno
store i32 %103, i32* @errno
%104 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%105 = load i32, i32* @EXIT_FAILURE
%106 = call i32 @exit(i32 %105)
unreachable
107: ; No predecessors!
br label %108
108: ; preds = %107, %97
%109 = load i32, i32* @EXIT_SUCCESS
%110 = call i32 @exit(i32 %109)
unreachable
}

LLVM IR (-O2):
@.str = [9 x i8] c"testfile\00"
@O_RDWR = global i32 0
@errno = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [6 x i8] c"lseek\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [5 x i8] c"%ld\0A\00"
@.str.5 = [26 x i8] c"%s: pid = %ld, seq = %ld\0A\00"
@.str.6 = [6 x i8] c"write\00"
@.str.7 = [6 x i8] c"close\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [11 x i8]
%4 = alloca i64
%5 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%6 = bitcast i64* %4 to i8*
%7 = tail call i64 (...) @getpid()
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %51
%16 = add nuw nsw i32 %19, 1
%17 = icmp eq i32 %16, 10
br i1 %17, label %59, label %18
18: ; preds = %2, %15
%19 = phi i32 [ %16, %15 ], [ 0, %2 ]
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @lseek(i32 %9, i32 0, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %18
%28 = call i32 @read(i32 %9, i8* %5, i32 10)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %27
%35 = sext i32 %28 to i64
%36 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 %35
store i8 0, i8* %36
%37 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64* %4)
%38 = load i8*, i8** %1
%39 = load i64, i64* %4
%40 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %38, i64 %7, i64 %39)
%41 = load i64, i64* %4
%42 = add nsw i64 %41, 1
store i64 %42, i64* %4
%43 = call i32 @snprintf(i8* %5, i32 11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %42)
%44 = load i32, i32* @SEEK_SET
%45 = call i32 @lseek(i32 %9, i32 0, i32 %44)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %51
47: ; preds = %34
%48 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %34
%52 = call i32 @strlen(i8* %5)
%53 = call i32 @write(i32 %9, i8* %5, i32 %52)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %15
55: ; preds = %51
%56 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %15
%60 = call i32 @close(i32 %9)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %66
62: ; preds = %59
%63 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @exit(i32 %64)
unreachable
66: ; preds = %59
%67 = load i32, i32* @EXIT_SUCCESS
%68 = call i32 @exit(i32 %67)
unreachable
}