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

/* Variables and functions */
int ENOENT;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ SEEK_SET;
int atoi(int /*<<< orphan*/);
scalar_t__ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(unsigned int *);
int getopt(int, char **, char *);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ malloc(unsigned int);
int open(char *, int, int);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ remove(char *);
char *strerror(int);
int /*<<< orphan*/ usage();
scalar_t__ write(int, unsigned int *, unsigned int);
int main(int argc, char *argv[]) {
  int fd = -1;
  ssize_t bytes_wrote;
  unsigned int *buf = NULL;
  unsigned int n, u, i;
  int temp;
  unsigned int iterations = 0;
  unsigned int num = 0;
  int opt = 0;
  if (argc != 5) {
    usage();
    exit(-1);
  }
  while ((opt = getopt(argc, argv, "n:i:")) != -1) {
    switch (opt) {
    case 'n':
      if ((temp = atoi(optarg)) < 0) {
        usage();
        exit(-1);
      }
      num = (unsigned int)temp;
      break;
    case 'i':
      if ((temp = atoi(optarg)) < 0) {
        usage();
        exit(-1);
      }
      iterations = (unsigned int)temp;
      break;
    default:
      printf("Invalid option encountered\n");
      break;
    }
  }
  printf("WRITER: # of integers to write = %u; # of iterations = %d\n", num,
         iterations);
  if (remove("atomic_data") < 0) {
    if (errno == ENOENT)
      printf("WRITER: remove %s--%s\n", "atomic_data", strerror(errno));
    else {
      printf("WRITER: error from remove: %d--%s\n", errno, strerror(errno));
      goto error;
    }
  } else
    printf("WRITER: %s is removed\n", "atomic_data");
  if ((fd = open("atomic_data", O_RDWR | O_TRUNC | O_CREAT, 0664)) < 0) {
    printf("WRITER: error from open\n");
    goto error;
  }
  if ((buf = (unsigned int *)malloc(num * sizeof(unsigned int))) == NULL) {
    printf("WRITER: error from malloc\n");
    if (fd >= 0 && close(fd) < 0)
      printf("WRITER: error from close\n");
    goto error;
  }
  printf("\n");
  for (i = 1; i <= iterations; i++) {
    printf("WRITER: *****start iteration %u*****\n", i);
    for (n = 0; n < num; n++) {
      for (u = 0; u < num; u++)
        buf[u] = n;
      if (lseek(fd, (off_t)(n * sizeof(unsigned int)), SEEK_SET) < 0) {
        printf("WRITER: error from lseek\n");
        goto error;
      }
      if ((bytes_wrote = write(fd, buf, ((num - n) * sizeof(unsigned int)))) <
          0) {
        printf("WRITER: error from write\n");
        goto error;
      }
      if (bytes_wrote != (ssize_t)((num - n) * sizeof(unsigned int))) {
        printf("WRITER: error from bytes written\n");
        goto error;
      }
    }
    printf("WRITER: *****end iteration %u*****\n\n", i);
  }
  if (close(fd) < 0) {
    printf("WRITER: error from close\n");
    goto error;
  }
  if (buf)
    free(buf);
  return (0);
error:
  return (-1);
}


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)
movl   $0xffffffff,-0x14(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     1225 <main+0x55>
mov    $0x0,%al
call   10a0 <usage@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
jmp    122a <main+0x5a>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdc8(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x44(%rbp)
cmp    $0xffffffff,%eax
je     12ed <main+0x11d>
mov    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
sub    $0x69,%eax
je     12a4 <main+0xd4>
jmp    125d <main+0x8d>
mov    -0x48(%rbp),%eax
sub    $0x6e,%eax
jne    12da <main+0x10a>
jmp    126e <main+0x9e>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   10d0 <atoi@plt>
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
jge    1299 <main+0xc9>
mov    $0x0,%al
call   10a0 <usage@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    12e8 <main+0x118>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
call   10d0 <atoi@plt>
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
jge    12cf <main+0xff>
mov    $0x0,%al
call   10a0 <usage@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    12e8 <main+0x118>
lea    0xd24(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    122a <main+0x5a>
mov    -0x40(%rbp),%esi
mov    -0x3c(%rbp),%edx
lea    0xd27(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd54(%rip),%rdi
call   1040 <remove@plt>
cmp    $0x0,%rax
jge    1392 <main+0x1c2>
mov    0x2ca2(%rip),%rax
mov    (%rax),%eax
mov    0x2c81(%rip),%rcx
cmp    (%rcx),%eax
jne    135a <main+0x18a>
mov    0x2c8a(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rdx
lea    0xd21(%rip),%rdi
lea    0xd0e(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    138d <main+0x1bd>
mov    0x2c5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2c53(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x4c(%rbp),%esi
mov    %rax,%rdx
lea    0xcfe(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15d3 <main+0x403>
jmp    13a7 <main+0x1d7>
lea    0xd09(%rip),%rdi
lea    0xcbc(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2c22(%rip),%rax
mov    (%rax),%esi
mov    0x2c31(%rip),%rax
or     (%rax),%esi
mov    0x2c38(%rip),%rax
or     (%rax),%esi
lea    0xc93(%rip),%rdi
mov    $0x1b4,%edx
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    13f2 <main+0x222>
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15d3 <main+0x403>
mov    -0x40(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    144b <main+0x27b>
lea    0xcbd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jl     1446 <main+0x276>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
jge    1446 <main+0x276>
lea    0xcae(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15d3 <main+0x403>
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x3c(%rbp),%eax
ja     158e <main+0x3be>
mov    -0x34(%rbp),%esi
lea    0xc91(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jae    156f <main+0x39f>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x40(%rbp),%eax
jae    14be <main+0x2ee>
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1497 <main+0x2c7>
mov    -0x14(%rbp),%edi
mov    -0x2c(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%esi
mov    0x2ae7(%rip),%rax
mov    (%rax),%edx
call   1070 <lseek@plt>
cmp    $0x0,%rax
jge    14f5 <main+0x325>
lea    0xc44(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15d3 <main+0x403>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x40(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,%eax
shl    $0x2,%rax
mov    %eax,%edx
call   1050 <write@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    1530 <main+0x360>
lea    0xc23(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15d3 <main+0x403>
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%ecx
sub    -0x2c(%rbp),%ecx
mov    %ecx,%ecx
shl    $0x2,%rcx
cmp    %rcx,%rax
je     155c <main+0x38c>
lea    0xc11(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15d3 <main+0x403>
jmp    1561 <main+0x391>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1484 <main+0x2b4>
mov    -0x34(%rbp),%esi
lea    0xc0a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1460 <main+0x290>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
jge    15b3 <main+0x3e3>
lea    0xb46(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15d3 <main+0x403>
cmpq   $0x0,-0x28(%rbp)
je     15c7 <main+0x3f7>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    15da <main+0x40a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
cmp    $0x5,%edi
jne    1279 <main+0x89>
mov    %rsi,%rbp
movl   $0x0,(%rsp)
lea    0xdec(%rip),%rbx
mov    0x2dd5(%rip),%r14
lea    0xf64(%rip),%r15
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x5,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   10e0 <getopt@plt>
cmp    $0xffffffff,%eax
je     128a <main+0x9a>
cmp    $0x69,%eax
je     1259 <main+0x69>
cmp    $0x6e,%eax
je     126a <main+0x7a>
mov    %r15,%rdi
call   1060 <puts@plt>
jmp    1230 <main+0x40>
mov    (%r14),%edi
call   10f0 <atoi@plt>
mov    %eax,(%rsp)
test   %eax,%eax
jns    1230 <main+0x40>
jmp    1279 <main+0x89>
mov    (%r14),%edi
call   10f0 <atoi@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    1230 <main+0x40>
xor    %eax,%eax
call   10c0 <usage@plt>
mov    $0xffffffff,%edi
call   1100 <exit@plt>
lea    0xd74(%rip),%rdi
mov    %r12d,%esi
mov    (%rsp),%edx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd9b(%rip),%rdi
call   1050 <remove@plt>
test   %rax,%rax
js     12c6 <main+0xd6>
lea    0xdd0(%rip),%rdi
lea    0xd83(%rip),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    12ff <main+0x10f>
mov    0x2cf3(%rip),%rax
mov    (%rax),%ebx
mov    0x2cd2(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1110 <strerror@plt>
cmp    %ebp,%ebx
jne    15e5 <main+0x3f5>
lea    0xd5e(%rip),%rdi
lea    0xd4b(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2cca(%rip),%rax
mov    0x2cdb(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2ce0(%rip),%rax
or     (%rax),%esi
lea    0xd1f(%rip),%rdi
mov    $0x1b4,%edx
call   10d0 <open@plt>
test   %eax,%eax
js     15ab <main+0x3bb>
mov    %eax,%r13d
lea    0x0(,%r12,4),%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     15b9 <main+0x3c9>
mov    %rax,%rbp
mov    $0xa,%edi
call   1040 <putchar@plt>
cmpl   $0x0,(%rsp)
je     158e <main+0x39e>
mov    %r12d,%ebx
mov    %ebx,%eax
and    $0xfffffff8,%eax
mov    %rax,0x30(%rsp)
add    $0xfffffffffffffff8,%rax
mov    %rax,0x28(%rsp)
shr    $0x3,%rax
add    $0x1,%rax
mov    %eax,%ecx
and    $0x7,%ecx
and    $0xfffffffffffffff8,%rax
mov    %rax,0x8(%rsp)
mov    %rbp,%rax
add    $0x10,%rax
mov    %rax,0x10(%rsp)
mov    %rcx,0x20(%rsp)
shl    $0x5,%rcx
mov    %rcx,0x18(%rsp)
mov    $0x1,%r14d
lea    0xce7(%rip),%rdi
mov    %r14d,0x4(%rsp)
mov    %r14d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
test   %r12d,%r12d
je     1563 <main+0x373>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x8,%r12d
jae    13f0 <main+0x200>
xor    %eax,%eax
jmp    14f0 <main+0x300>
nopl   (%rax)
movd   %r15d,%xmm0
pshufd $0x0,%xmm0,%xmm0
cmpq   $0x38,0x28(%rsp)
mov    0x18(%rsp),%rdx
jae    1410 <main+0x220>
xor    %eax,%eax
jmp    14a6 <main+0x2b6>
xchg   %ax,%ax
mov    0x8(%rsp),%rcx
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movdqu %xmm0,0x0(%rbp,%rax,4)
movdqu %xmm0,0x10(%rbp,%rax,4)
movdqu %xmm0,0x20(%rbp,%rax,4)
movdqu %xmm0,0x30(%rbp,%rax,4)
movdqu %xmm0,0x40(%rbp,%rax,4)
movdqu %xmm0,0x50(%rbp,%rax,4)
movdqu %xmm0,0x60(%rbp,%rax,4)
movdqu %xmm0,0x70(%rbp,%rax,4)
movdqu %xmm0,0x80(%rbp,%rax,4)
movdqu %xmm0,0x90(%rbp,%rax,4)
movdqu %xmm0,0xa0(%rbp,%rax,4)
movdqu %xmm0,0xb0(%rbp,%rax,4)
movdqu %xmm0,0xc0(%rbp,%rax,4)
movdqu %xmm0,0xd0(%rbp,%rax,4)
movdqu %xmm0,0xe0(%rbp,%rax,4)
movdqu %xmm0,0xf0(%rbp,%rax,4)
add    $0x40,%rax
add    $0xfffffffffffffff8,%rcx
jne    1420 <main+0x230>
cmpq   $0x0,0x20(%rsp)
je     14d4 <main+0x2e4>
mov    0x10(%rsp),%rcx
lea    (%rcx,%rax,4),%rax
xor    %ecx,%ecx
nopl   0x0(%rax)
movdqu %xmm0,-0x10(%rax,%rcx,1)
movdqu %xmm0,(%rax,%rcx,1)
add    $0x20,%rcx
cmp    %rcx,%rdx
jne    14c0 <main+0x2d0>
mov    0x30(%rsp),%rcx
mov    %rcx,%rax
cmp    %rbx,%rcx
je     14fe <main+0x30e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,0x0(%rbp,%rax,4)
add    $0x1,%rax
cmp    %rax,%rbx
jne    14f0 <main+0x300>
lea    0x0(,%r15,4),%esi
mov    0x2aab(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
call   1090 <lseek@plt>
test   %rax,%rax
js     160e <main+0x41e>
mov    %r13d,%edi
mov    %r12,%r14
mov    %r12d,%r13d
sub    %r15d,%r13d
shl    $0x2,%r13
mov    %edi,%r12d
mov    %rbp,%rsi
mov    %r13d,%edx
call   1070 <write@plt>
test   %rax,%rax
js     1617 <main+0x427>
cmp    %r13,%rax
jne    1620 <main+0x430>
add    $0x1,%r15
cmp    %rbx,%r15
mov    %r12d,%r13d
mov    %r14,%r12
jne    13e0 <main+0x1f0>
lea    0xb59(%rip),%rdi
mov    0x4(%rsp),%r14d
mov    %r14d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
add    $0x1,%r14d
cmp    (%rsp),%r14d
lea    0xb15(%rip),%rdi
jbe    13b6 <main+0x1c6>
mov    %r13d,%edi
call   10a0 <close@plt>
test   %rax,%rax
js     1629 <main+0x439>
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
jmp    15fd <main+0x40d>
lea    0xbbc(%rip),%rdi
call   1060 <puts@plt>
jmp    15f8 <main+0x408>
lea    0xb7b(%rip),%rdi
call   1060 <puts@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jns    15fd <main+0x40d>
lea    0xb77(%rip),%rdi
call   1060 <puts@plt>
jmp    15fd <main+0x40d>
lea    0xa77(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb0d(%rip),%rdi
jmp    15b2 <main+0x3c2>
lea    0xaeb(%rip),%rdi
jmp    15b2 <main+0x3c2>
lea    0xac1(%rip),%rdi
jmp    15b2 <main+0x3c2>
lea    0xb25(%rip),%rdi
jmp    15b2 <main+0x3c2>

LLVM IR (-O0):
@.str = [5 x i8] c"n:i:\00"
@optarg = global i32 0
@.str.1 = [28 x i8] c"Invalid option encountered\0A\00"
@.str.2 = [59 x i8] c"WRITER: # of integers to write = %u; # of iterations = %d\0A\00"
@.str.3 = [12 x i8] c"atomic_data\00"
@errno = global i32 0
@ENOENT = global i32 0
@.str.4 = [23 x i8] c"WRITER: remove %s--%s\0A\00"
@.str.5 = [35 x i8] c"WRITER: error from remove: %d--%s\0A\00"
@.str.6 = [23 x i8] c"WRITER: %s is removed\0A\00"
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.7 = [25 x i8] c"WRITER: error from open\0A\00"
@.str.8 = [27 x i8] c"WRITER: error from malloc\0A\00"
@.str.9 = [26 x i8] c"WRITER: error from close\0A\00"
@.str.10 = [2 x i8] c"\0A\00"
@.str.11 = [38 x i8] c"WRITER: *****start iteration %u*****\0A\00"
@SEEK_SET = global i32 0
@.str.12 = [26 x i8] c"WRITER: error from lseek\0A\00"
@.str.13 = [26 x i8] c"WRITER: error from write\0A\00"
@.str.14 = [34 x i8] c"WRITER: error from bytes written\0A\00"
@.str.15 = [37 x i8] c"WRITER: *****end iteration %u*****\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32* null, i32** %8
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 5
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 (...) @usage()
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %2
br label %22
22: ; preds = %49, %21
%23 = load i32, i32* %4
%24 = load i8**, i8*** %5
%25 = call i32 @getopt(i32 %23, i8** %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %25, i32* %15
%26 = icmp ne i32 %25, -1
br i1 %26, label %27, label %50
27: ; preds = %22
%28 = load i32, i32* %15
switch i32 %28, label %47 [
i32 110, label %29
i32 105, label %38
]
29: ; preds = %27
%30 = load i32, i32* @optarg
%31 = call i32 @atoi(i32 %30)
store i32 %31, i32* %12
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = call i32 (...) @usage()
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %29
%37 = load i32, i32* %12
store i32 %37, i32* %14
br label %49
38: ; preds = %27
%39 = load i32, i32* @optarg
%40 = call i32 @atoi(i32 %39)
store i32 %40, i32* %12
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = call i32 (...) @usage()
%44 = call i32 @exit(i32 -1)
unreachable
45: ; preds = %38
%46 = load i32, i32* %12
store i32 %46, i32* %13
br label %49
47: ; preds = %27
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %49
49: ; preds = %47, %45, %36
br label %22
50: ; preds = %22
%51 = load i32, i32* %14
%52 = load i32, i32* %13
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32 %51, i32 %52)
%54 = call i64 @remove(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %70
56: ; preds = %50
%57 = load i32, i32* @errno
%58 = load i32, i32* @ENOENT
%59 = icmp eq i32 %57, %58
br i1 %59, label %60, label %64
60: ; preds = %56
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %62)
br label %69
64: ; preds = %56
%65 = load i32, i32* @errno
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %65, i8* %67)
br label %185
69: ; preds = %60
br label %72
70: ; preds = %50
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %72
72: ; preds = %70, %69
%73 = load i32, i32* @O_RDWR
%74 = load i32, i32* @O_TRUNC
%75 = or i32 %73, %74
%76 = load i32, i32* @O_CREAT
%77 = or i32 %75, %76
%78 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %77, i32 436)
store i32 %78, i32* %6
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %72
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
br label %185
82: ; preds = %72
%83 = load i32, i32* %14
%84 = zext i32 %83 to i64
%85 = mul i64 %84, 4
%86 = trunc i64 %85 to i32
%87 = call i64 @malloc(i32 %86)
%88 = inttoptr i64 %87 to i32*
store i32* %88, i32** %8
%89 = icmp eq i32* %88, null
br i1 %89, label %90, label %101
90: ; preds = %82
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%92 = load i32, i32* %6
%93 = icmp sge i32 %92, 0
br i1 %93, label %94, label %100
94: ; preds = %90
%95 = load i32, i32* %6
%96 = call i64 @close(i32 %95)
%97 = icmp slt i64 %96, 0
br i1 %97, label %98, label %100
98: ; preds = %94
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %100
100: ; preds = %98, %94, %90
br label %185
101: ; preds = %82
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %11
br label %103
103: ; preds = %169, %101
%104 = load i32, i32* %11
%105 = load i32, i32* %13
%106 = icmp ule i32 %104, %105
br i1 %106, label %107, label %172
107: ; preds = %103
%108 = load i32, i32* %11
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.11, i64 0, i64 0), i32 %108)
store i32 0, i32* %9
br label %110
110: ; preds = %163, %107
%111 = load i32, i32* %9
%112 = load i32, i32* %14
%113 = icmp ult i32 %111, %112
br i1 %113, label %114, label %166
114: ; preds = %110
store i32 0, i32* %10
br label %115
115: ; preds = %125, %114
%116 = load i32, i32* %10
%117 = load i32, i32* %14
%118 = icmp ult i32 %116, %117
br i1 %118, label %119, label %128
119: ; preds = %115
%120 = load i32, i32* %9
%121 = load i32*, i32** %8
%122 = load i32, i32* %10
%123 = zext i32 %122 to i64
%124 = getelementptr inbounds i32, i32* %121, i64 %123
store i32 %120, i32* %124
br label %125
125: ; preds = %119
%126 = load i32, i32* %10
%127 = add i32 %126, 1
store i32 %127, i32* %10
br label %115
128: ; preds = %115
%129 = load i32, i32* %6
%130 = load i32, i32* %9
%131 = zext i32 %130 to i64
%132 = mul i64 %131, 4
%133 = trunc i64 %132 to i32
%134 = load i32, i32* @SEEK_SET
%135 = call i64 @lseek(i32 %129, i32 %133, i32 %134)
%136 = icmp slt i64 %135, 0
br i1 %136, label %137, label %139
137: ; preds = %128
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0))
br label %185
139: ; preds = %128
%140 = load i32, i32* %6
%141 = load i32*, i32** %8
%142 = load i32, i32* %14
%143 = load i32, i32* %9
%144 = sub i32 %142, %143
%145 = zext i32 %144 to i64
%146 = mul i64 %145, 4
%147 = trunc i64 %146 to i32
%148 = call i64 @write(i32 %140, i32* %141, i32 %147)
store i64 %148, i64* %7
%149 = icmp slt i64 %148, 0
br i1 %149, label %150, label %152
150: ; preds = %139
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0))
br label %185
152: ; preds = %139
%153 = load i64, i64* %7
%154 = load i32, i32* %14
%155 = load i32, i32* %9
%156 = sub i32 %154, %155
%157 = zext i32 %156 to i64
%158 = mul i64 %157, 4
%159 = icmp ne i64 %153, %158
br i1 %159, label %160, label %162
160: ; preds = %152
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.14, i64 0, i64 0))
br label %185
162: ; preds = %152
br label %163
163: ; preds = %162
%164 = load i32, i32* %9
%165 = add i32 %164, 1
store i32 %165, i32* %9
br label %110
166: ; preds = %110
%167 = load i32, i32* %11
%168 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.15, i64 0, i64 0), i32 %167)
br label %169
169: ; preds = %166
%170 = load i32, i32* %11
%171 = add i32 %170, 1
store i32 %171, i32* %11
br label %103
172: ; preds = %103
%173 = load i32, i32* %6
%174 = call i64 @close(i32 %173)
%175 = icmp slt i64 %174, 0
br i1 %175, label %176, label %178
176: ; preds = %172
%177 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %185
178: ; preds = %172
%179 = load i32*, i32** %8
%180 = icmp ne i32* %179, null
br i1 %180, label %181, label %184
181: ; preds = %178
%182 = load i32*, i32** %8
%183 = call i32 @free(i32* %182)
br label %184
184: ; preds = %181, %178
store i32 0, i32* %3
br label %186
185: ; preds = %176, %160, %150, %137, %100, %80, %64
store i32 -1, i32* %3
br label %186
186: ; preds = %185, %184
%187 = load i32, i32* %3
ret i32 %187
}

LLVM IR (-O2):
@.str = [5 x i8] c"n:i:\00"
@optarg = global i32 0
@.str.2 = [59 x i8] c"WRITER: # of integers to write = %u; # of iterations = %d\0A\00"
@.str.3 = [12 x i8] c"atomic_data\00"
@errno = global i32 0
@ENOENT = global i32 0
@.str.4 = [23 x i8] c"WRITER: remove %s--%s\0A\00"
@.str.5 = [35 x i8] c"WRITER: error from remove: %d--%s\0A\00"
@.str.6 = [23 x i8] c"WRITER: %s is removed\0A\00"
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.11 = [38 x i8] c"WRITER: *****start iteration %u*****\0A\00"
@SEEK_SET = global i32 0
@.str.15 = [37 x i8] c"WRITER: *****end iteration %u*****\0A\0A\00"
@str.16 = [33 x i8] c"WRITER: error from bytes written\00"
@str.17 = [25 x i8] c"WRITER: error from write\00"
@str.18 = [25 x i8] c"WRITER: error from lseek\00"
@str.19 = [26 x i8] c"WRITER: error from malloc\00"
@str.20 = [25 x i8] c"WRITER: error from close\00"
@str.21 = [24 x i8] c"WRITER: error from open\00"
@str.22 = [27 x i8] c"Invalid option encountered\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp eq i32 %0, 5
br i1 %3, label %22, label %4
4: ; preds = %2
%5 = tail call i32 (...) @usage()
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %13, %28
%8 = tail call i32 @getopt(i32 5, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %8, label %28 [
i32 -1, label %30
i32 110, label %9
i32 105, label %18
]
9: ; preds = %7
%10 = load i32, i32* @optarg
%11 = tail call i32 @atoi(i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %22, %9
%14 = phi i32 [ %24, %22 ], [ %11, %9 ]
br label %7
15: ; preds = %9
%16 = tail call i32 (...) @usage()
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %7
%19 = load i32, i32* @optarg
%20 = tail call i32 @atoi(i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %2, %18
%23 = phi i32 [ %20, %18 ], [ 0, %2 ]
%24 = phi i32 [ %14, %18 ], [ 0, %2 ]
br label %13
25: ; preds = %18
%26 = tail call i32 (...) @usage()
%27 = tail call i32 @exit(i32 -1)
unreachable
28: ; preds = %7
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.22, i64 0, i64 0))
br label %7
30: ; preds = %7
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %23)
%32 = tail call i64 @remove(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %30
%35 = load i32, i32* @errno
%36 = load i32, i32* @ENOENT
%37 = icmp eq i32 %35, %36
%38 = tail call i8* @strerror(i32 %35)
br i1 %37, label %39, label %41
39: ; preds = %34
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %38)
br label %45
41: ; preds = %34
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %35, i8* %38)
br label %194
43: ; preds = %30
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %45
45: ; preds = %43, %39
%46 = load i32, i32* @O_RDWR
%47 = load i32, i32* @O_TRUNC
%48 = or i32 %47, %46
%49 = load i32, i32* @O_CREAT
%50 = or i32 %48, %49
%51 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %50, i32 436)
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %45
%54 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.21, i64 0, i64 0))
br label %194
55: ; preds = %45
%56 = shl i32 %14, 2
%57 = tail call i64 @malloc(i32 %56)
%58 = inttoptr i64 %57 to i32*
%59 = icmp eq i64 %57, 0
br i1 %59, label %60, label %66
60: ; preds = %55
%61 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.19, i64 0, i64 0))
%62 = tail call i64 @close(i32 %51)
%63 = icmp slt i64 %62, 0
br i1 %63, label %64, label %194
64: ; preds = %60
%65 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.20, i64 0, i64 0))
br label %194
66: ; preds = %55
%67 = tail call i32 @putchar(i32 10)
%68 = icmp eq i32 %23, 0
br i1 %68, label %187, label %69
69: ; preds = %66
%70 = icmp eq i32 %14, 0
%71 = zext i32 %14 to i64
%72 = and i64 %71, 4294967288
%73 = add nsw i64 %72, -8
%74 = lshr exact i64 %73, 3
%75 = add nuw nsw i64 %74, 1
%76 = icmp ult i32 %14, 8
%77 = and i64 %71, 4294967288
%78 = and i64 %75, 7
%79 = icmp ult i64 %73, 56
%80 = and i64 %75, 4611686018427387896
%81 = icmp eq i64 %78, 0
%82 = icmp eq i64 %77, %71
br label %83
83: ; preds = %69, %183
%84 = phi i32 [ 1, %69 ], [ %185, %183 ]
%85 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.11, i64 0, i64 0), i32 %84)
br i1 %70, label %183, label %88
86: ; preds = %178
%87 = icmp eq i64 %180, %71
br i1 %87, label %183, label %88
88: ; preds = %83, %86
%89 = phi i64 [ %180, %86 ], [ 0, %83 ]
%90 = trunc i64 %89 to i32
br i1 %76, label %154, label %91
91: ; preds = %88
%92 = insertelement <4 x i32> poison, i32 %90, i64 0
%93 = shufflevector <4 x i32> %92, <4 x i32> poison, <4 x i32> zeroinitializer
%94 = insertelement <4 x i32> poison, i32 %90, i64 0
%95 = shufflevector <4 x i32> %94, <4 x i32> poison, <4 x i32> zeroinitializer
br i1 %79, label %141, label %96
96: ; preds = %91, %96
%97 = phi i64 [ %138, %96 ], [ 0, %91 ]
%98 = phi i64 [ %139, %96 ], [ 0, %91 ]
%99 = getelementptr inbounds i32, i32* %58, i64 %97
%100 = bitcast i32* %99 to <4 x i32>*
store <4 x i32> %93, <4 x i32>* %100
%101 = getelementptr inbounds i32, i32* %99, i64 4
%102 = bitcast i32* %101 to <4 x i32>*
store <4 x i32> %95, <4 x i32>* %102
%103 = or i64 %97, 8
%104 = getelementptr inbounds i32, i32* %58, i64 %103
%105 = bitcast i32* %104 to <4 x i32>*
store <4 x i32> %93, <4 x i32>* %105
%106 = getelementptr inbounds i32, i32* %104, i64 4
%107 = bitcast i32* %106 to <4 x i32>*
store <4 x i32> %95, <4 x i32>* %107
%108 = or i64 %97, 16
%109 = getelementptr inbounds i32, i32* %58, i64 %108
%110 = bitcast i32* %109 to <4 x i32>*
store <4 x i32> %93, <4 x i32>* %110
%111 = getelementptr inbounds i32, i32* %109, i64 4
%112 = bitcast i32* %111 to <4 x i32>*
store <4 x i32> %95, <4 x i32>* %112
%113 = or i64 %97, 24
%114 = getelementptr inbounds i32, i32* %58, i64 %113
%115 = bitcast i32* %114 to <4 x i32>*
store <4 x i32> %93, <4 x i32>* %115
%116 = getelementptr inbounds i32, i32* %114, i64 4
%117 = bitcast i32* %116 to <4 x i32>*
store <4 x i32> %95, <4 x i32>* %117
%118 = or i64 %97, 32
%119 = getelementptr inbounds i32, i32* %58, i64 %118
%120 = bitcast i32* %119 to <4 x i32>*
store <4 x i32> %93, <4 x i32>* %120
%121 = getelementptr inbounds i32, i32* %119, i64 4
%122 = bitcast i32* %121 to <4 x i32>*
store <4 x i32> %95, <4 x i32>* %122
%123 = or i64 %97, 40
%124 = getelementptr inbounds i32, i32* %58, i64 %123
%125 = bitcast i32* %124 to <4 x i32>*
store <4 x i32> %93, <4 x i32>* %125
%126 = getelementptr inbounds i32, i32* %124, i64 4
%127 = bitcast i32* %126 to <4 x i32>*
store <4 x i32> %95, <4 x i32>* %127
%128 = or i64 %97, 48
%129 = getelementptr inbounds i32, i32* %58, i64 %128
%130 = bitcast i32* %129 to <4 x i32>*
store <4 x i32> %93, <4 x i32>* %130
%131 = getelementptr inbounds i32, i32* %129, i64 4
%132 = bitcast i32* %131 to <4 x i32>*
store <4 x i32> %95, <4 x i32>* %132
%133 = or i64 %97, 56
%134 = getelementptr inbounds i32, i32* %58, i64 %133
%135 = bitcast i32* %134 to <4 x i32>*
store <4 x i32> %93, <4 x i32>* %135
%136 = getelementptr inbounds i32, i32* %134, i64 4
%137 = bitcast i32* %136 to <4 x i32>*
store <4 x i32> %95, <4 x i32>* %137
%138 = add nuw i64 %97, 64
%139 = add nuw i64 %98, 8
%140 = icmp eq i64 %139, %80
br i1 %140, label %141, label %96
141: ; preds = %96, %91
%142 = phi i64 [ 0, %91 ], [ %138, %96 ]
br i1 %81, label %153, label %143
143: ; preds = %141, %143
%144 = phi i64 [ %150, %143 ], [ %142, %141 ]
%145 = phi i64 [ %151, %143 ], [ 0, %141 ]
%146 = getelementptr inbounds i32, i32* %58, i64 %144
%147 = bitcast i32* %146 to <4 x i32>*
store <4 x i32> %93, <4 x i32>* %147
%148 = getelementptr inbounds i32, i32* %146, i64 4
%149 = bitcast i32* %148 to <4 x i32>*
store <4 x i32> %95, <4 x i32>* %149
%150 = add nuw i64 %144, 8
%151 = add i64 %145, 1
%152 = icmp eq i64 %151, %78
br i1 %152, label %153, label %143
153: ; preds = %143, %141
br i1 %82, label %161, label %154
154: ; preds = %88, %153
%155 = phi i64 [ 0, %88 ], [ %77, %153 ]
br label %156
156: ; preds = %154, %156
%157 = phi i64 [ %159, %156 ], [ %155, %154 ]
%158 = getelementptr inbounds i32, i32* %58, i64 %157
store i32 %90, i32* %158
%159 = add nuw nsw i64 %157, 1
%160 = icmp eq i64 %159, %71
br i1 %160, label %161, label %156
161: ; preds = %156, %153
%162 = trunc i64 %89 to i32
%163 = shl i32 %162, 2
%164 = load i32, i32* @SEEK_SET
%165 = tail call i64 @lseek(i32 %51, i32 %163, i32 %164)
%166 = icmp slt i64 %165, 0
br i1 %166, label %167, label %169
167: ; preds = %161
%168 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.18, i64 0, i64 0))
br label %194
169: ; preds = %161
%170 = sub i32 %14, %162
%171 = zext i32 %170 to i64
%172 = shl nuw nsw i64 %171, 2
%173 = trunc i64 %172 to i32
%174 = tail call i64 @write(i32 %51, i32* %58, i32 %173)
%175 = icmp slt i64 %174, 0
br i1 %175, label %176, label %178
176: ; preds = %169
%177 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.17, i64 0, i64 0))
br label %194
178: ; preds = %169
%179 = icmp eq i64 %174, %172
%180 = add nuw nsw i64 %89, 1
br i1 %179, label %86, label %181
181: ; preds = %178
%182 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.16, i64 0, i64 0))
br label %194
183: ; preds = %86, %83
%184 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.15, i64 0, i64 0), i32 %84)
%185 = add i32 %84, 1
%186 = icmp ugt i32 %185, %23
br i1 %186, label %187, label %83
187: ; preds = %183, %66
%188 = tail call i64 @close(i32 %51)
%189 = icmp slt i64 %188, 0
br i1 %189, label %190, label %192
190: ; preds = %187
%191 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.20, i64 0, i64 0))
br label %194
192: ; preds = %187
%193 = tail call i32 @free(i32* %58)
br label %194
194: ; preds = %41, %53, %167, %176, %181, %190, %64, %60, %192
%195 = phi i32 [ 0, %192 ], [ -1, %60 ], [ -1, %64 ], [ -1, %190 ], [ -1, %181 ], [ -1, %176 ], [ -1, %167 ], [ -1, %53 ], [ -1, %41 ]
ret i32 %195
}