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

/* Variables and functions */
scalar_t__ EEXIST;
scalar_t__ ENOENT;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int atol(char *);
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ eout(char *, ...);
scalar_t__ errno;
int /*<<< orphan*/ isdigit(char);
scalar_t__ link(char *, char *);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int rand();
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int, long);
int /*<<< orphan*/ strerror(scalar_t__);
int strlen(char *);
int /*<<< orphan*/ unlink(char *);
int write(int, char *, int);
long get_next_seq(void) {
  char buf[100];
  int try = 0;
  long s = -1;
  int fd, l;
again:
  if (link(".Sequence", "LCK..seq") < 0) {
    if (errno == EEXIST) {
      if (++try < 3) {
        eout("sequence file locked (try %d)...\n", try);
        sleep(rand() % 3 + 1);
        goto again;
      }
      eout("can't lock sequence file, give up\n");
      return -1;
    }
    if (errno == ENOENT) {
      eout("sequence file does not exist, creating...\n");
      fd = creat(".Sequence", 0644);
      if (fd < 0) {
        eout("can't create sequence file '%s': %s\n", ".Sequence",
             strerror(errno));
        return -1;
      }
      write(fd, "000000\n", 7);
      close(fd);
      goto again;
    }
    eout("can't lock sequence file: %s\n", strerror(errno));
    return -1;
  }
  fd = open(".Sequence", O_RDWR);
  if (fd < 0) {
    eout("can't open '%s' read/write: %s\n", ".Sequence", strerror(errno));
    goto unlock_and_out;
  }
  l = read(fd, buf, sizeof(buf) - 1);
  if (l >= 0)
    buf[l] = '\0';
  if (l < 0 || l >= sizeof(buf) - 1 || !isdigit(buf[0])) {
    eout("sequence file '%s' corrupt\n", ".Sequence");
    goto close_and_out;
  }
  s = atol(buf) + 1;
  sprintf(buf, "%0*ld\n", l - 1, s);
  if (lseek(fd, 0, SEEK_SET) != 0) {
    eout("can't rewind sequence file: %s\n", strerror(errno));
    goto close_and_out;
  }
  l = strlen(buf);
  if (write(fd, buf, l) != l) {
    eout("can't write all %d bytes to %s: %s\n", l, ".Sequence",
         strerror(errno));
  }
close_and_out:
  close(fd);
unlock_and_out:
  unlink("LCK..seq");
  return s;
}


x86 assembly (clang, -O0):
<get_next_seq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x74(%rbp)
movq   $0xffffffffffffffff,-0x80(%rbp)
ff
lea    0xddf(%rip),%rdi
lea    0xde2(%rip),%rsi
call   10f0 <link@plt>
cmp    $0x0,%rax
jge    137f <get_next_seq+0x17f>
mov    0x2d92(%rip),%rax
mov    (%rax),%rax
mov    0x2d90(%rip),%rcx
cmp    (%rcx),%rax
jne    12ad <get_next_seq+0xad>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
cmp    $0x3,%eax
jge    1292 <get_next_seq+0x92>
mov    -0x74(%rbp),%esi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   10c0 <eout@plt>
mov    $0x0,%al
call   1120 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
add    $0x1,%edi
call   1110 <sleep@plt>
jmp    121a <get_next_seq+0x1a>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   10c0 <eout@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    154e <get_next_seq+0x34e>
mov    0x2d1c(%rip),%rax
mov    (%rax),%rax
mov    0x2cfa(%rip),%rcx
cmp    (%rcx),%rax
jne    1353 <get_next_seq+0x153>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   10c0 <eout@plt>
lea    0xd24(%rip),%rdi
mov    $0x1a4,%esi
call   10d0 <creat@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jge    132c <get_next_seq+0x12c>
mov    0x2cd0(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    %eax,%edx
lea    0xd72(%rip),%rdi
lea    0xce8(%rip),%rsi
mov    $0x0,%al
call   10c0 <eout@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    154e <get_next_seq+0x34e>
mov    -0x84(%rbp),%edi
lea    0xd6f(%rip),%rsi
mov    $0x7,%edx
call   1050 <write@plt>
mov    -0x84(%rbp),%edi
call   1080 <close@plt>
jmp    121a <get_next_seq+0x1a>
mov    0x2c76(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    %eax,%esi
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   10c0 <eout@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    154e <get_next_seq+0x34e>
mov    0x2c62(%rip),%rax
mov    (%rax),%esi
lea    0xc71(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jge    13d2 <get_next_seq+0x1d2>
mov    0x2c22(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    %eax,%edx
lea    0xd0f(%rip),%rdi
lea    0xc3a(%rip),%rsi
mov    $0x0,%al
call   10c0 <eout@plt>
jmp    153a <get_next_seq+0x33a>
mov    -0x84(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x63,%edx
call   1090 <read@plt>
mov    %eax,-0x88(%rbp)
cmpl   $0x0,-0x88(%rbp)
jl     1405 <get_next_seq+0x205>
movslq -0x88(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
cmpl   $0x0,-0x88(%rbp)
jl     1435 <get_next_seq+0x235>
movslq -0x88(%rbp),%rax
cmp    $0x63,%rax
jae    1435 <get_next_seq+0x235>
movsbl -0x70(%rbp),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    144f <get_next_seq+0x24f>
lea    0xcb2(%rip),%rdi
lea    0xbbd(%rip),%rsi
mov    $0x0,%al
call   10c0 <eout@plt>
jmp    152f <get_next_seq+0x32f>
lea    -0x70(%rbp),%rdi
call   10a0 <atol@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x80(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x88(%rbp),%edx
sub    $0x1,%edx
mov    -0x80(%rbp),%rcx
lea    0xc91(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x84(%rbp),%edi
mov    0x2b3d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <lseek@plt>
cmp    $0x0,%rax
je     14c2 <get_next_seq+0x2c2>
mov    0x2b2b(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    %eax,%esi
lea    0xc5b(%rip),%rdi
mov    $0x0,%al
call   10c0 <eout@plt>
jmp    152f <get_next_seq+0x32f>
lea    -0x70(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x88(%rbp)
mov    -0x84(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    -0x88(%rbp),%edx
call   1050 <write@plt>
cmp    -0x88(%rbp),%eax
je     152a <get_next_seq+0x32a>
mov    -0x88(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    0x2acb(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    -0x8c(%rbp),%esi
mov    %eax,%ecx
lea    0xc15(%rip),%rdi
lea    0xadd(%rip),%rdx
mov    $0x0,%al
call   10c0 <eout@plt>
jmp    152f <get_next_seq+0x32f>
mov    -0x84(%rbp),%edi
call   1080 <close@plt>
lea    0xac9(%rip),%rdi
call   1030 <unlink@plt>
mov    -0x80(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_seq>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xdeb(%rip),%rdi
lea    0xdee(%rip),%rsi
call   10f0 <link@plt>
test   %rax,%rax
js     1302 <get_next_seq+0x102>
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
lea    0xdc6(%rip),%rdi
call   10b0 <open@plt>
test   %eax,%eax
js     13a0 <get_next_seq+0x1a0>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x63,%edx
call   1090 <read@plt>
test   %eax,%eax
js     12da <get_next_seq+0xda>
mov    %eax,%ebp
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
cmp    $0x62,%ebp
ja     12da <get_next_seq+0xda>
movsbl (%rsp),%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     12da <get_next_seq+0xda>
mov    %rsp,%r15
mov    %r15,%rdi
call   10a0 <atol@plt>
add    $0x1,%eax
movslq %eax,%r14
add    $0xffffffff,%ebp
lea    0xe79(%rip),%rsi
mov    %r15,%rdi
mov    %ebp,%edx
mov    %r14,%rcx
call   10e0 <sprintf@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
test   %rax,%rax
je     14e0 <get_next_seq+0x2e0>
mov    0x2d10(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
lea    0xe42(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10c0 <eout@plt>
jmp    12f6 <get_next_seq+0xf6>
lea    0xe0d(%rip),%rdi
lea    0xd18(%rip),%rsi
xor    %eax,%eax
call   10c0 <eout@plt>
mov    $0xffffffffffffffff,%r14
mov    %ebx,%edi
call   1080 <close@plt>
jmp    13cd <get_next_seq+0x1cd>
mov    0x2cc7(%rip),%r13
lea    0xd48(%rip),%r14
lea    0xce9(%rip),%rbx
lea    0xd8a(%rip),%r15
lea    0xce5(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13),%rdi
mov    0x2c9d(%rip),%rax
cmp    (%rax),%rdi
je     13eb <get_next_seq+0x1eb>
mov    0x2c6d(%rip),%rax
cmp    (%rax),%rdi
jne    160e <get_next_seq+0x40e>
mov    %r14,%rdi
xor    %eax,%eax
call   10c0 <eout@plt>
mov    %rbx,%rdi
mov    $0x1a4,%esi
call   10d0 <creat@plt>
test   %eax,%eax
js     162f <get_next_seq+0x42f>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x7,%edx
call   1050 <write@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10f0 <link@plt>
test   %rax,%rax
js     1330 <get_next_seq+0x130>
jmp    122a <get_next_seq+0x2a>
mov    0x2c29(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
lea    0xd18(%rip),%rdi
lea    0xc43(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10c0 <eout@plt>
mov    $0xffffffffffffffff,%r14
lea    0xc36(%rip),%rdi
call   1030 <unlink@plt>
mov    %r14,%rax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc21(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   10c0 <eout@plt>
xor    %eax,%eax
call   1120 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%edi
add    $0x1,%edi
call   1110 <sleep@plt>
lea    0xbce(%rip),%rdi
lea    0xbd1(%rip),%rsi
call   10f0 <link@plt>
test   %rax,%rax
jns    122a <get_next_seq+0x2a>
lea    0xc0a(%rip),%r14
lea    0xbab(%rip),%rbx
lea    0xc4c(%rip),%r15
lea    0xba7(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13),%rdi
mov    0x2b5d(%rip),%rax
cmp    (%rax),%rdi
je     152e <get_next_seq+0x32e>
mov    0x2b2d(%rip),%rax
cmp    (%rax),%rdi
jne    160e <get_next_seq+0x40e>
mov    %r14,%rdi
xor    %eax,%eax
call   10c0 <eout@plt>
mov    %rbx,%rdi
mov    $0x1a4,%esi
call   10d0 <creat@plt>
test   %eax,%eax
js     162f <get_next_seq+0x42f>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x7,%edx
call   1050 <write@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10f0 <link@plt>
test   %rax,%rax
js     1470 <get_next_seq+0x270>
jmp    122a <get_next_seq+0x2a>
mov    %rsp,%r15
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    %ebp,%eax
je     12f6 <get_next_seq+0xf6>
mov    0x2ac8(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
lea    0xc1a(%rip),%rdi
lea    0xae2(%rip),%rdx
mov    %ebp,%esi
mov    %eax,%ecx
xor    %eax,%eax
call   10c0 <eout@plt>
jmp    12f6 <get_next_seq+0xf6>
lea    0xade(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   10c0 <eout@plt>
xor    %eax,%eax
call   1120 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%edi
add    $0x1,%edi
call   1110 <sleep@plt>
lea    0xa8b(%rip),%rdi
lea    0xa8e(%rip),%rsi
call   10f0 <link@plt>
test   %rax,%rax
jns    122a <get_next_seq+0x2a>
lea    0xac7(%rip),%r14
lea    0xa68(%rip),%rbx
lea    0xb09(%rip),%r15
lea    0xa64(%rip),%r12
mov    0x0(%r13),%rdi
mov    0x2a27(%rip),%rax
cmp    (%rax),%rdi
je     165b <get_next_seq+0x45b>
mov    0x29f7(%rip),%rax
cmp    (%rax),%rdi
jne    160e <get_next_seq+0x40e>
mov    %r14,%rdi
xor    %eax,%eax
call   10c0 <eout@plt>
mov    %rbx,%rdi
mov    $0x1a4,%esi
call   10d0 <creat@plt>
test   %eax,%eax
js     162f <get_next_seq+0x42f>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x7,%edx
call   1050 <write@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10f0 <link@plt>
test   %rax,%rax
js     15a6 <get_next_seq+0x3a6>
jmp    122a <get_next_seq+0x2a>
call   1100 <strerror@plt>
lea    0xa96(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10c0 <eout@plt>
mov    $0xffffffffffffffff,%r14
jmp    13d9 <get_next_seq+0x1d9>
mov    0x0(%r13),%rdi
call   1100 <strerror@plt>
lea    0xa44(%rip),%rdi
lea    0x9ba(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10c0 <eout@plt>
mov    $0xffffffffffffffff,%r14
jmp    13d9 <get_next_seq+0x1d9>
lea    0x9d3(%rip),%rdi
xor    %eax,%eax
call   10c0 <eout@plt>
mov    $0xffffffffffffffff,%r14
jmp    13d9 <get_next_seq+0x1d9>

LLVM IR (-O0):
@.str = [10 x i8] c".Sequence\00"
@.str.1 = [9 x i8] c"LCK..seq\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.2 = [34 x i8] c"sequence file locked (try %d)...\0A\00"
@.str.3 = [35 x i8] c"can't lock sequence file, give up\0A\00"
@ENOENT = global i64 0
@.str.4 = [43 x i8] c"sequence file does not exist, creating...\0A\00"
@.str.5 = [37 x i8] c"can't create sequence file '%s': %s\0A\00"
@.str.6 = [8 x i8] c"000000\0A\00"
@.str.7 = [30 x i8] c"can't lock sequence file: %s\0A\00"
@O_RDWR = global i32 0
@.str.8 = [32 x i8] c"can't open '%s' read/write: %s\0A\00"
@.str.9 = [28 x i8] c"sequence file '%s' corrupt\0A\00"
@.str.10 = [7 x i8] c"%0*ld\0A\00"
@SEEK_SET = global i32 0
@.str.11 = [32 x i8] c"can't rewind sequence file: %s\0A\00"
@.str.12 = [36 x i8] c"can't write all %d bytes to %s: %s\0A\00"
define i64 @get_next_seq() {
%1 = alloca i64
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %3
store i64 -1, i64* %4
br label %7
7: ; preds = %40, %18, %0
%8 = call i64 @link(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %49
10: ; preds = %7
%11 = load i64, i64* @errno
%12 = load i64, i64* @EEXIST
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %27
14: ; preds = %10
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load i32, i32* %3
%20 = call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = call i32 (...) @rand()
%22 = srem i32 %21, 3
%23 = add nsw i32 %22, 1
%24 = call i32 @sleep(i32 %23)
br label %7
25: ; preds = %14
%26 = call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
store i64 -1, i64* %1
br label %121
27: ; preds = %10
%28 = load i64, i64* @errno
%29 = load i64, i64* @ENOENT
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %45
31: ; preds = %27
%32 = call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%33 = call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 420)
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i64, i64* @errno
%38 = call i32 @strerror(i64 %37)
%39 = call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %38)
store i64 -1, i64* %1
br label %121
40: ; preds = %31
%41 = load i32, i32* %5
%42 = call i32 @write(i32 %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 7)
%43 = load i32, i32* %5
%44 = call i32 @close(i32 %43)
br label %7
45: ; preds = %27
%46 = load i64, i64* @errno
%47 = call i32 @strerror(i64 %46)
%48 = call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %47)
store i64 -1, i64* %1
br label %121
49: ; preds = %7
%50 = load i32, i32* @O_RDWR
%51 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %50)
store i32 %51, i32* %5
%52 = load i32, i32* %5
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %49
%55 = load i64, i64* @errno
%56 = call i32 @strerror(i64 %55)
%57 = call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %56)
br label %118
58: ; preds = %49
%59 = load i32, i32* %5
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%61 = call i32 @read(i32 %59, i8* %60, i32 99)
store i32 %61, i32* %6
%62 = load i32, i32* %6
%63 = icmp sge i32 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %58
%65 = load i32, i32* %6
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %66
store i8 0, i8* %67
br label %68
68: ; preds = %64, %58
%69 = load i32, i32* %6
%70 = icmp slt i32 %69, 0
br i1 %70, label %80, label %71
71: ; preds = %68
%72 = load i32, i32* %6
%73 = sext i32 %72 to i64
%74 = icmp uge i64 %73, 99
br i1 %74, label %80, label %75
75: ; preds = %71
%76 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%77 = load i8, i8* %76
%78 = call i32 @isdigit(i8 signext %77)
%79 = icmp ne i32 %78, 0
br i1 %79, label %82, label %80
80: ; preds = %75, %71, %68
%81 = call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %115
82: ; preds = %75
%83 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%84 = call i32 @atol(i8* %83)
%85 = add nsw i32 %84, 1
%86 = sext i32 %85 to i64
store i64 %86, i64* %4
%87 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%88 = load i32, i32* %6
%89 = sub nsw i32 %88, 1
%90 = load i64, i64* %4
%91 = call i32 @sprintf(i8* %87, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %89, i64 %90)
%92 = load i32, i32* %5
%93 = load i32, i32* @SEEK_SET
%94 = call i64 @lseek(i32 %92, i32 0, i32 %93)
%95 = icmp ne i64 %94, 0
br i1 %95, label %96, label %100
96: ; preds = %82
%97 = load i64, i64* @errno
%98 = call i32 @strerror(i64 %97)
%99 = call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0), i32 %98)
br label %115
100: ; preds = %82
%101 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%102 = call i32 @strlen(i8* %101)
store i32 %102, i32* %6
%103 = load i32, i32* %5
%104 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%105 = load i32, i32* %6
%106 = call i32 @write(i32 %103, i8* %104, i32 %105)
%107 = load i32, i32* %6
%108 = icmp ne i32 %106, %107
br i1 %108, label %109, label %114
109: ; preds = %100
%110 = load i32, i32* %6
%111 = load i64, i64* @errno
%112 = call i32 @strerror(i64 %111)
%113 = call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0), i32 %110, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %112)
br label %114
114: ; preds = %109, %100
br label %115
115: ; preds = %114, %96, %80
%116 = load i32, i32* %5
%117 = call i32 @close(i32 %116)
br label %118
118: ; preds = %115, %54
%119 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%120 = load i64, i64* %4
store i64 %120, i64* %1
br label %121
121: ; preds = %118, %45, %36, %25
%122 = load i64, i64* %1
ret i64 %122
}

LLVM IR (-O2):
@.str = [10 x i8] c".Sequence\00"
@.str.1 = [9 x i8] c"LCK..seq\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.2 = [34 x i8] c"sequence file locked (try %d)...\0A\00"
@.str.3 = [35 x i8] c"can't lock sequence file, give up\0A\00"
@ENOENT = global i64 0
@.str.4 = [43 x i8] c"sequence file does not exist, creating...\0A\00"
@.str.5 = [37 x i8] c"can't create sequence file '%s': %s\0A\00"
@.str.6 = [8 x i8] c"000000\0A\00"
@.str.7 = [30 x i8] c"can't lock sequence file: %s\0A\00"
@O_RDWR = global i32 0
@.str.8 = [32 x i8] c"can't open '%s' read/write: %s\0A\00"
@.str.9 = [28 x i8] c"sequence file '%s' corrupt\0A\00"
@.str.10 = [7 x i8] c"%0*ld\0A\00"
@SEEK_SET = global i32 0
@.str.11 = [32 x i8] c"can't rewind sequence file: %s\0A\00"
@.str.12 = [36 x i8] c"can't write all %d bytes to %s: %s\0A\00"
define i64 @get_next_seq() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i64 @link(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %79
5: ; preds = %0, %70
%6 = load i64, i64* @errno
%7 = load i64, i64* @EEXIST
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %59
9: ; preds = %5
%10 = tail call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 1)
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 3
%13 = add nsw i32 %12, 1
%14 = tail call i32 @sleep(i32 %13)
%15 = tail call i64 @link(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %79
17: ; preds = %9, %28
%18 = load i64, i64* @errno
%19 = load i64, i64* @EEXIST
%20 = icmp eq i64 %18, %19
br i1 %20, label %33, label %21
21: ; preds = %17
%22 = load i64, i64* @ENOENT
%23 = icmp eq i64 %18, %22
br i1 %23, label %24, label %75
24: ; preds = %21
%25 = tail call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%26 = tail call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 420)
%27 = icmp slt i32 %26, 0
br i1 %27, label %66, label %28
28: ; preds = %24
%29 = tail call i32 @write(i32 %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 7)
%30 = tail call i32 @close(i32 %26)
%31 = tail call i64 @link(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp slt i64 %31, 0
br i1 %32, label %17, label %79
33: ; preds = %17
%34 = tail call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 2)
%35 = tail call i32 (...) @rand()
%36 = srem i32 %35, 3
%37 = add nsw i32 %36, 1
%38 = tail call i32 @sleep(i32 %37)
%39 = tail call i64 @link(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %79
41: ; preds = %33, %52
%42 = load i64, i64* @errno
%43 = load i64, i64* @EEXIST
%44 = icmp eq i64 %42, %43
br i1 %44, label %57, label %45
45: ; preds = %41
%46 = load i64, i64* @ENOENT
%47 = icmp eq i64 %42, %46
br i1 %47, label %48, label %75
48: ; preds = %45
%49 = tail call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%50 = tail call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 420)
%51 = icmp slt i32 %50, 0
br i1 %51, label %66, label %52
52: ; preds = %48
%53 = tail call i32 @write(i32 %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 7)
%54 = tail call i32 @close(i32 %50)
%55 = tail call i64 @link(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%56 = icmp slt i64 %55, 0
br i1 %56, label %41, label %79
57: ; preds = %41
%58 = tail call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %127
59: ; preds = %5
%60 = load i64, i64* @ENOENT
%61 = icmp eq i64 %6, %60
br i1 %61, label %62, label %75
62: ; preds = %59
%63 = tail call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%64 = tail call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 420)
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %62, %24, %48
%67 = load i64, i64* @errno
%68 = tail call i32 @strerror(i64 %67)
%69 = tail call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %68)
br label %127
70: ; preds = %62
%71 = tail call i32 @write(i32 %64, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 7)
%72 = tail call i32 @close(i32 %64)
%73 = tail call i64 @link(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%74 = icmp slt i64 %73, 0
br i1 %74, label %5, label %79
75: ; preds = %59, %21, %45
%76 = phi i64 [ %42, %45 ], [ %18, %21 ], [ %6, %59 ]
%77 = tail call i32 @strerror(i64 %76)
%78 = tail call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %77)
br label %127
79: ; preds = %70, %28, %52, %9, %33, %0
%80 = load i32, i32* @O_RDWR
%81 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %80)
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %87
83: ; preds = %79
%84 = load i64, i64* @errno
%85 = tail call i32 @strerror(i64 %84)
%86 = tail call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %85)
br label %124
87: ; preds = %79
%88 = call i32 @read(i32 %81, i8* %2, i32 99)
%89 = icmp sgt i32 %88, -1
br i1 %89, label %90, label %98
90: ; preds = %87
%91 = zext i32 %88 to i64
%92 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %91
store i8 0, i8* %92
%93 = icmp ugt i32 %88, 98
br i1 %93, label %98, label %94
94: ; preds = %90
%95 = load i8, i8* %2
%96 = tail call i32 @isdigit(i8 signext %95)
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %100
98: ; preds = %87, %94, %90
%99 = tail call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %121
100: ; preds = %94
%101 = call i32 @atol(i8* %2)
%102 = add nsw i32 %101, 1
%103 = sext i32 %102 to i64
%104 = add nsw i32 %88, -1
%105 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %104, i64 %103)
%106 = load i32, i32* @SEEK_SET
%107 = tail call i64 @lseek(i32 %81, i32 0, i32 %106)
%108 = icmp eq i64 %107, 0
br i1 %108, label %113, label %109
109: ; preds = %100
%110 = load i64, i64* @errno
%111 = tail call i32 @strerror(i64 %110)
%112 = tail call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0), i32 %111)
br label %121
113: ; preds = %100
%114 = call i32 @strlen(i8* %2)
%115 = call i32 @write(i32 %81, i8* %2, i32 %114)
%116 = icmp eq i32 %115, %114
br i1 %116, label %121, label %117
117: ; preds = %113
%118 = load i64, i64* @errno
%119 = call i32 @strerror(i64 %118)
%120 = call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0), i32 %114, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %119)
br label %121
121: ; preds = %113, %117, %109, %98
%122 = phi i64 [ -1, %98 ], [ %103, %109 ], [ %103, %117 ], [ %103, %113 ]
%123 = call i32 @close(i32 %81)
br label %124
124: ; preds = %121, %83
%125 = phi i64 [ -1, %83 ], [ %122, %121 ]
%126 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %127
127: ; preds = %124, %75, %66, %57
%128 = phi i64 [ -1, %57 ], [ -1, %66 ], [ -1, %75 ], [ %125, %124 ]
ret i64 %128
}