#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  void *sigev_notify;
};
struct aiocb {
  int aio_fildes;
  int aio_nbytes;
  int aio_offset;
  TYPE_1__ aio_sigevent;
  scalar_t__ aio_reqprio;
  void *aio_buf;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int O_TRUNC;
int RAND_MAX;
void *SIGEV_NONE;
int /*<<< orphan*/ aio_read(struct aiocb *);
int /*<<< orphan*/ aio_suspend(struct aiocb const *const *, int,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ aio_write(struct aiocb *);
int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getpid();
int *malloc(int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ rand();
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int time(int /*<<< orphan*/ *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int i, nb_proc, total;
  if (argc != 2 || !strcmp(argv[1], "-h")) {
    fprintf(stderr, "usage: %s NB_THREADS\n", argv[0]);
    return EXIT_FAILURE;
  }
  nb_proc = atoi(argv[1]);
  total = 0;
  char *path = "random.ipc";
  int fd;
  if ((fd = open(path, O_RDONLY | O_CREAT | O_TRUNC, 0644)) == -1) {
    perror("unable to open IPC file");
    return EXIT_FAILURE;
  }
  for (i = 0; i < nb_proc; ++i) {
    if (fork() == 0) {
      srand(time(NULL) ^ (getpid() << 16));
      int rand_val = (int)(10 * (float)rand() / RAND_MAX);
      if ((fd = open(path, O_RDWR)) == -1) {
        perror("[%d] unable to reopen IPC file");
        return EXIT_FAILURE;
      }
      struct aiocb aio;
      aio.aio_fildes = fd;
      aio.aio_buf = (void *)&rand_val;
      aio.aio_nbytes = sizeof(int);
      aio.aio_offset = i * sizeof(int);
      aio.aio_reqprio = 0;
      aio.aio_sigevent.sigev_notify = SIGEV_NONE;
      aio_write(&aio);
      struct aiocb const *const aios = &aio;
      aio_suspend(&aios, 1, NULL);
      close(fd);
      return EXIT_SUCCESS;
    }
  }
  for (i = 0; i < nb_proc; ++i)
    wait(NULL);
  int *buf = malloc(sizeof(int *) * nb_proc);
  struct aiocb aio;
  aio.aio_fildes = fd;
  aio.aio_buf = (void *)buf;
  aio.aio_nbytes = nb_proc * sizeof(int);
  aio.aio_offset = 0;
  aio.aio_reqprio = 0;
  aio.aio_sigevent.sigev_notify = SIGEV_NONE;
  aio_read(&aio);
  struct aiocb const *const aios = &aio;
  aio_suspend(&aios, 1, NULL);
  for (i = 0; i < nb_proc; ++i) {
    total += buf[i];
  }
  printf("total = %d\n", total);
  close(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1250 <main+0x40>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc2(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    127d <main+0x6d>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xda0(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    152d <main+0x31d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xd82(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
mov    0x2d45(%rip),%rax
or     (%rax),%esi
mov    0x2d34(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    12f3 <main+0xe3>
lea    0xd4b(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2cbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    152d <main+0x31d>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    142d <main+0x21d>
mov    $0x0,%al
call   1120 <fork@plt>
cmp    $0x0,%rax
jne    141a <main+0x20a>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,-0x9c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x9c(%rbp),%edi
shl    $0x10,%eax
xor    %eax,%edi
call   1070 <srand@plt>
mov    $0x0,%al
call   1130 <rand@plt>
cvtsi2ss %rax,%xmm1
movss  0xcaf(%rip),%xmm0
mulss  %xmm1,%xmm0
mov    0x2c64(%rip),%rax
cvtsi2ssl (%rax),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2c5a(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    13a8 <main+0x198>
lea    0xcae(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2c0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    152d <main+0x31d>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x58(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x4,-0x54(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,-0x50(%rbp)
movq   $0x0,-0x40(%rbp)
mov    0x2c11(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
lea    -0x58(%rbp),%rdi
call   1040 <aio_write@plt>
lea    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
call   10d0 <aio_suspend@plt>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
mov    0x2b90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    152d <main+0x31d>
jmp    141f <main+0x20f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12fa <main+0xea>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1457 <main+0x247>
xor    %eax,%eax
mov    %eax,%edi
call   1110 <wait@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1434 <main+0x224>
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x90(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x70(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,-0x8c(%rbp)
movl   $0x0,-0x88(%rbp)
movq   $0x0,-0x78(%rbp)
mov    0x2b46(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x80(%rbp)
lea    -0x90(%rbp),%rdi
call   10a0 <aio_read@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x98(%rbp),%rdi
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
call   10d0 <aio_suspend@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    150a <main+0x2fa>
mov    -0x68(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    14df <main+0x2cf>
mov    -0x1c(%rbp),%esi
lea    0xb4b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
mov    0x2a78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1343 <main+0x133>
mov    0x8(%rbx),%rbp
lea    0xdd3(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
je     1343 <main+0x133>
mov    %rbp,%rdi
call   1100 <atoi@plt>
mov    0x2d78(%rip),%rcx
mov    0x2da1(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    %eax,%r15d
mov    0x2d8b(%rip),%rax
or     (%rax),%esi
lea    0xdaf(%rip),%rdi
mov    $0x1a4,%edx
xor    %eax,%eax
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     1556 <main+0x346>
mov    %eax,%r14d
test   %r15d,%r15d
jle    12bc <main+0xac>
mov    %r15d,%ebx
xor    %ebp,%ebp
xor    %eax,%eax
call   1120 <fork@plt>
test   %rax,%rax
je     1367 <main+0x157>
add    $0x4,%ebp
add    $0xffffffff,%ebx
jne    1290 <main+0x80>
test   %r15d,%r15d
jle    12bc <main+0xac>
mov    %r15d,%ebx
xor    %edi,%edi
call   1110 <wait@plt>
add    $0xffffffff,%ebx
jne    12b0 <main+0xa0>
lea    0x0(,%r15,8),%edi
call   10c0 <malloc@plt>
mov    %rax,%rbx
mov    %r14d,0x10(%rsp)
mov    %rax,0x30(%rsp)
lea    0x0(,%r15,4),%eax
mov    %eax,0x14(%rsp)
movl   $0x0,0x18(%rsp)
movq   $0x0,0x28(%rsp)
mov    0x2cee(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x20(%rsp)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   10a0 <aio_read@plt>
mov    %rbp,(%rsp)
xor    %ebp,%ebp
mov    %rsp,%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   10d0 <aio_suspend@plt>
test   %r15d,%r15d
jle    152c <main+0x31c>
mov    %r15d,%eax
cmp    $0x8,%r15d
jae    1429 <main+0x219>
xor    %ecx,%ecx
xor    %ebp,%ebp
jmp    1520 <main+0x310>
mov    0x2c66(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xcb1(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2c46(%rip),%rax
jmp    1549 <main+0x339>
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
shl    $0x10,%eax
xor    %eax,%ebx
mov    %ebx,%edi
call   1070 <srand@plt>
xor    %eax,%eax
call   1130 <rand@plt>
cvtsi2ss %rax,%xmm0
mulss  0xc69(%rip),%xmm0
mov    0x2c22(%rip),%rax
cvtsi2ssl (%rax),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,0xc(%rsp)
mov    0x2c1b(%rip),%rax
mov    (%rax),%esi
lea    0xc5f(%rip),%rdi
xor    %eax,%eax
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     155f <main+0x34f>
mov    %eax,%ebx
mov    %eax,0x10(%rsp)
lea    0xc(%rsp),%rax
mov    %rax,0x30(%rsp)
movl   $0x4,0x14(%rsp)
mov    %ebp,0x18(%rsp)
movq   $0x0,0x28(%rsp)
mov    0x2bee(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x20(%rsp)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <aio_write@plt>
mov    %rbp,(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   10d0 <aio_suspend@plt>
mov    %ebx,%edi
jmp    153d <main+0x32d>
mov    %eax,%ecx
and    $0xfffffff8,%ecx
lea    -0x8(%rcx),%rsi
mov    %rsi,%rdi
shr    $0x3,%rdi
add    $0x1,%rdi
mov    %edi,%edx
and    $0x3,%edx
cmp    $0x18,%rsi
jae    1454 <main+0x244>
pxor   %xmm0,%xmm0
xor    %esi,%esi
pxor   %xmm1,%xmm1
jmp    14c9 <main+0x2b9>
and    $0xfffffffffffffffc,%rdi
pxor   %xmm0,%xmm0
xor    %esi,%esi
pxor   %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movdqu (%rbx,%rsi,4),%xmm2
paddd  %xmm0,%xmm2
movdqu 0x10(%rbx,%rsi,4),%xmm0
paddd  %xmm1,%xmm0
movdqu 0x20(%rbx,%rsi,4),%xmm1
movdqu 0x30(%rbx,%rsi,4),%xmm3
movdqu 0x40(%rbx,%rsi,4),%xmm4
paddd  %xmm1,%xmm4
paddd  %xmm2,%xmm4
movdqu 0x50(%rbx,%rsi,4),%xmm2
paddd  %xmm3,%xmm2
paddd  %xmm0,%xmm2
movdqu 0x60(%rbx,%rsi,4),%xmm0
paddd  %xmm4,%xmm0
movdqu 0x70(%rbx,%rsi,4),%xmm1
paddd  %xmm2,%xmm1
add    $0x20,%rsi
add    $0xfffffffffffffffc,%rdi
jne    1470 <main+0x260>
test   %rdx,%rdx
je     14fc <main+0x2ec>
lea    (%rbx,%rsi,4),%rsi
add    $0x10,%rsi
shl    $0x5,%rdx
xor    %edi,%edi
nopl   0x0(%rax)
movdqu -0x10(%rsi,%rdi,1),%xmm2
paddd  %xmm2,%xmm0
movdqu (%rsi,%rdi,1),%xmm2
paddd  %xmm2,%xmm1
add    $0x20,%rdi
cmp    %rdi,%rdx
jne    14e0 <main+0x2d0>
paddd  %xmm1,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%ebp
cmp    %rax,%rcx
je     152c <main+0x31c>
nopl   0x0(%rax,%rax,1)
add    (%rbx,%rcx,4),%ebp
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1520 <main+0x310>
lea    0xb2c(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    0x2a57(%rip),%rax
mov    (%rax),%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xacb(%rip),%rdi
jmp    1566 <main+0x356>
lea    0xada(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2a36(%rip),%rax
jmp    1549 <main+0x339>

LLVM IR (-O0):
%struct.aiocb = type { i32, i32, i32, %struct.TYPE_2__, i64, i8* }
%struct.TYPE_2__ = type { i8* }
@.str = [3 x i8] c"-h\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"usage: %s NB_THREADS\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [11 x i8] c"random.ipc\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [24 x i8] c"unable to open IPC file\00"
@RAND_MAX = global i32 0
@O_RDWR = global i32 0
@.str.4 = [31 x i8] c"[%d] unable to reopen IPC file\00"
@SIGEV_NONE = global i8* null
@EXIT_SUCCESS = global i32 0
@.str.5 = [12 x i8] c"total = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.aiocb
%13 = alloca %struct.aiocb*
%14 = alloca i32*
%15 = alloca %struct.aiocb
%16 = alloca %struct.aiocb*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 2
br i1 %18, label %25, label %19
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %19, %2
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
store i32 %31, i32* %3
br label %154
32: ; preds = %19
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %7
store i32 0, i32* %8
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** %9
%37 = load i8*, i8** %9
%38 = load i32, i32* @O_RDONLY
%39 = load i32, i32* @O_CREAT
%40 = or i32 %38, %39
%41 = load i32, i32* @O_TRUNC
%42 = or i32 %40, %41
%43 = call i32 (i8*, i32, ...) @open(i8* %37, i32 %42, i32 420)
store i32 %43, i32* %10
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %32
%46 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
store i32 %47, i32* %3
br label %154
48: ; preds = %32
store i32 0, i32* %6
br label %49
49: ; preds = %97, %48
%50 = load i32, i32* %6
%51 = load i32, i32* %7
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %100
53: ; preds = %49
%54 = call i64 (...) @fork()
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %96
56: ; preds = %53
%57 = call i32 @time(i32* null)
%58 = call i32 (...) @getpid()
%59 = shl i32 %58, 16
%60 = xor i32 %57, %59
%61 = call i32 @srand(i32 %60)
%62 = call i64 (...) @rand()
%63 = sitofp i64 %62 to float
%64 = fmul float 1.000000e+01, %63
%65 = load i32, i32* @RAND_MAX
%66 = sitofp i32 %65 to float
%67 = fdiv float %64, %66
%68 = fptosi float %67 to i32
store i32 %68, i32* %11
%69 = load i8*, i8** %9
%70 = load i32, i32* @O_RDWR
%71 = call i32 (i8*, i32, ...) @open(i8* %69, i32 %70)
store i32 %71, i32* %10
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %76
73: ; preds = %56
%74 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%75 = load i32, i32* @EXIT_FAILURE
store i32 %75, i32* %3
br label %154
76: ; preds = %56
%77 = load i32, i32* %10
%78 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %12, i32 0, i32 0
store i32 %77, i32* %78
%79 = bitcast i32* %11 to i8*
%80 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %12, i32 0, i32 5
store i8* %79, i8** %80
%81 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %12, i32 0, i32 1
store i32 4, i32* %81
%82 = load i32, i32* %6
%83 = sext i32 %82 to i64
%84 = mul i64 %83, 4
%85 = trunc i64 %84 to i32
%86 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %12, i32 0, i32 2
store i32 %85, i32* %86
%87 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %12, i32 0, i32 4
store i64 0, i64* %87
%88 = load i8*, i8** @SIGEV_NONE
%89 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %12, i32 0, i32 3
%90 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %89, i32 0, i32 0
store i8* %88, i8** %90
%91 = call i32 @aio_write(%struct.aiocb* %12)
store %struct.aiocb* %12, %struct.aiocb** %13
%92 = call i32 @aio_suspend(%struct.aiocb** %13, i32 1, i32* null)
%93 = load i32, i32* %10
%94 = call i32 @close(i32 %93)
%95 = load i32, i32* @EXIT_SUCCESS
store i32 %95, i32* %3
br label %154
96: ; preds = %53
br label %97
97: ; preds = %96
%98 = load i32, i32* %6
%99 = add nsw i32 %98, 1
store i32 %99, i32* %6
br label %49
100: ; preds = %49
store i32 0, i32* %6
br label %101
101: ; preds = %107, %100
%102 = load i32, i32* %6
%103 = load i32, i32* %7
%104 = icmp slt i32 %102, %103
br i1 %104, label %105, label %110
105: ; preds = %101
%106 = call i32 @wait(i32* null)
br label %107
107: ; preds = %105
%108 = load i32, i32* %6
%109 = add nsw i32 %108, 1
store i32 %109, i32* %6
br label %101
110: ; preds = %101
%111 = load i32, i32* %7
%112 = sext i32 %111 to i64
%113 = mul i64 8, %112
%114 = trunc i64 %113 to i32
%115 = call i32* @malloc(i32 %114)
store i32* %115, i32** %14
%116 = load i32, i32* %10
%117 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %15, i32 0, i32 0
store i32 %116, i32* %117
%118 = load i32*, i32** %14
%119 = bitcast i32* %118 to i8*
%120 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %15, i32 0, i32 5
store i8* %119, i8** %120
%121 = load i32, i32* %7
%122 = sext i32 %121 to i64
%123 = mul i64 %122, 4
%124 = trunc i64 %123 to i32
%125 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %15, i32 0, i32 1
store i32 %124, i32* %125
%126 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %15, i32 0, i32 2
store i32 0, i32* %126
%127 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %15, i32 0, i32 4
store i64 0, i64* %127
%128 = load i8*, i8** @SIGEV_NONE
%129 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %15, i32 0, i32 3
%130 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %129, i32 0, i32 0
store i8* %128, i8** %130
%131 = call i32 @aio_read(%struct.aiocb* %15)
store %struct.aiocb* %15, %struct.aiocb** %16
%132 = call i32 @aio_suspend(%struct.aiocb** %16, i32 1, i32* null)
store i32 0, i32* %6
br label %133
133: ; preds = %145, %110
%134 = load i32, i32* %6
%135 = load i32, i32* %7
%136 = icmp slt i32 %134, %135
br i1 %136, label %137, label %148
137: ; preds = %133
%138 = load i32*, i32** %14
%139 = load i32, i32* %6
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds i32, i32* %138, i64 %140
%142 = load i32, i32* %141
%143 = load i32, i32* %8
%144 = add nsw i32 %143, %142
store i32 %144, i32* %8
br label %145
145: ; preds = %137
%146 = load i32, i32* %6
%147 = add nsw i32 %146, 1
store i32 %147, i32* %6
br label %133
148: ; preds = %133
%149 = load i32, i32* %8
%150 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %149)
%151 = load i32, i32* %10
%152 = call i32 @close(i32 %151)
%153 = load i32, i32* @EXIT_SUCCESS
store i32 %153, i32* %3
br label %154
154: ; preds = %148, %76, %73, %45, %25
%155 = load i32, i32* %3
ret i32 %155
}

LLVM IR (-O2):
%struct.aiocb = type { i32, i32, i32, %struct.TYPE_2__, i64, i8* }
%struct.TYPE_2__ = type { i8* }
@.str = [3 x i8] c"-h\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"usage: %s NB_THREADS\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [11 x i8] c"random.ipc\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [24 x i8] c"unable to open IPC file\00"
@RAND_MAX = global i32 0
@O_RDWR = global i32 0
@.str.4 = [31 x i8] c"[%d] unable to reopen IPC file\00"
@SIGEV_NONE = global i8* null
@EXIT_SUCCESS = global i32 0
@.str.5 = [12 x i8] c"total = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.aiocb
%5 = alloca %struct.aiocb*
%6 = alloca %struct.aiocb
%7 = alloca %struct.aiocb*
%8 = icmp eq i32 %0, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %9, %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
br label %200
19: ; preds = %9
%20 = tail call i32 @atoi(i8* %11)
%21 = load i32, i32* @O_RDONLY
%22 = load i32, i32* @O_CREAT
%23 = or i32 %22, %21
%24 = load i32, i32* @O_TRUNC
%25 = or i32 %23, %24
%26 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %25, i32 420)
%27 = icmp eq i32 %26, -1
br i1 %27, label %30, label %28
28: ; preds = %19
%29 = icmp sgt i32 %20, 0
br i1 %29, label %34, label %84
30: ; preds = %19
%31 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
br label %200
33: ; preds = %76
br i1 %29, label %79, label %84
34: ; preds = %28, %76
%35 = phi i32 [ %77, %76 ], [ 0, %28 ]
%36 = tail call i64 (...) @fork()
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %76
38: ; preds = %34
%39 = tail call i32 @time(i32* null)
%40 = tail call i32 (...) @getpid()
%41 = shl i32 %40, 16
%42 = xor i32 %41, %39
%43 = tail call i32 @srand(i32 %42)
%44 = bitcast i32* %3 to i8*
%45 = tail call i64 (...) @rand()
%46 = sitofp i64 %45 to float
%47 = fmul float %46, 1.000000e+01
%48 = load i32, i32* @RAND_MAX
%49 = sitofp i32 %48 to float
%50 = fdiv float %47, %49
%51 = fptosi float %50 to i32
store i32 %51, i32* %3
%52 = load i32, i32* @O_RDWR
%53 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %52)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %58
55: ; preds = %38
%56 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
br label %74
58: ; preds = %38
%59 = bitcast %struct.aiocb* %4 to i8*
%60 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %4, i64 0, i32 0
store i32 %53, i32* %60
%61 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %4, i64 0, i32 5
%62 = bitcast i8** %61 to i32**
store i32* %3, i32** %62
%63 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %4, i64 0, i32 1
store i32 4, i32* %63
%64 = shl i32 %35, 2
%65 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %4, i64 0, i32 2
store i32 %64, i32* %65
%66 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %4, i64 0, i32 4
store i64 0, i64* %66
%67 = load i8*, i8** @SIGEV_NONE
%68 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %4, i64 0, i32 3, i32 0
store i8* %67, i8** %68
%69 = call i32 @aio_write(%struct.aiocb* %4)
%70 = bitcast %struct.aiocb** %5 to i8*
store %struct.aiocb* %4, %struct.aiocb** %5
%71 = call i32 @aio_suspend(%struct.aiocb** %5, i32 1, i32* null)
%72 = call i32 @close(i32 %53)
%73 = load i32, i32* @EXIT_SUCCESS
br label %74
74: ; preds = %58, %55
%75 = phi i32 [ %57, %55 ], [ %73, %58 ]
br label %200
76: ; preds = %34
%77 = add nuw nsw i32 %35, 1
%78 = icmp eq i32 %77, %20
br i1 %78, label %33, label %34
79: ; preds = %33, %79
%80 = phi i32 [ %82, %79 ], [ 0, %33 ]
%81 = tail call i32 @wait(i32* null)
%82 = add nuw nsw i32 %80, 1
%83 = icmp eq i32 %82, %20
br i1 %83, label %84, label %79
84: ; preds = %79, %28, %33
%85 = shl i32 %20, 3
%86 = tail call i32* @malloc(i32 %85)
%87 = bitcast %struct.aiocb* %6 to i8*
%88 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %6, i64 0, i32 0
store i32 %26, i32* %88
%89 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %6, i64 0, i32 5
%90 = bitcast i8** %89 to i32**
store i32* %86, i32** %90
%91 = shl i32 %20, 2
%92 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %6, i64 0, i32 1
store i32 %91, i32* %92
%93 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %6, i64 0, i32 2
store i32 0, i32* %93
%94 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %6, i64 0, i32 4
store i64 0, i64* %94
%95 = load i8*, i8** @SIGEV_NONE
%96 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %6, i64 0, i32 3, i32 0
store i8* %95, i8** %96
%97 = call i32 @aio_read(%struct.aiocb* %6)
%98 = bitcast %struct.aiocb** %7 to i8*
store %struct.aiocb* %6, %struct.aiocb** %7
%99 = call i32 @aio_suspend(%struct.aiocb** %7, i32 1, i32* null)
br i1 %29, label %100, label %195
100: ; preds = %84
%101 = zext i32 %20 to i64
%102 = icmp ult i32 %20, 8
br i1 %102, label %184, label %103
103: ; preds = %100
%104 = and i64 %101, 4294967288
%105 = add nsw i64 %104, -8
%106 = lshr exact i64 %105, 3
%107 = add nuw nsw i64 %106, 1
%108 = and i64 %107, 3
%109 = icmp ult i64 %105, 24
br i1 %109, label %155, label %110
110: ; preds = %103
%111 = and i64 %107, 4611686018427387900
br label %112
112: ; preds = %112, %110
%113 = phi i64 [ 0, %110 ], [ %152, %112 ]
%114 = phi <4 x i32> [ zeroinitializer, %110 ], [ %150, %112 ]
%115 = phi <4 x i32> [ zeroinitializer, %110 ], [ %151, %112 ]
%116 = phi i64 [ 0, %110 ], [ %153, %112 ]
%117 = getelementptr inbounds i32, i32* %86, i64 %113
%118 = bitcast i32* %117 to <4 x i32>*
%119 = load <4 x i32>, <4 x i32>* %118
%120 = getelementptr inbounds i32, i32* %117, i64 4
%121 = bitcast i32* %120 to <4 x i32>*
%122 = load <4 x i32>, <4 x i32>* %121
%123 = add <4 x i32> %119, %114
%124 = add <4 x i32> %122, %115
%125 = or i64 %113, 8
%126 = getelementptr inbounds i32, i32* %86, i64 %125
%127 = bitcast i32* %126 to <4 x i32>*
%128 = load <4 x i32>, <4 x i32>* %127
%129 = getelementptr inbounds i32, i32* %126, i64 4
%130 = bitcast i32* %129 to <4 x i32>*
%131 = load <4 x i32>, <4 x i32>* %130
%132 = add <4 x i32> %128, %123
%133 = add <4 x i32> %131, %124
%134 = or i64 %113, 16
%135 = getelementptr inbounds i32, i32* %86, i64 %134
%136 = bitcast i32* %135 to <4 x i32>*
%137 = load <4 x i32>, <4 x i32>* %136
%138 = getelementptr inbounds i32, i32* %135, i64 4
%139 = bitcast i32* %138 to <4 x i32>*
%140 = load <4 x i32>, <4 x i32>* %139
%141 = add <4 x i32> %137, %132
%142 = add <4 x i32> %140, %133
%143 = or i64 %113, 24
%144 = getelementptr inbounds i32, i32* %86, i64 %143
%145 = bitcast i32* %144 to <4 x i32>*
%146 = load <4 x i32>, <4 x i32>* %145
%147 = getelementptr inbounds i32, i32* %144, i64 4
%148 = bitcast i32* %147 to <4 x i32>*
%149 = load <4 x i32>, <4 x i32>* %148
%150 = add <4 x i32> %146, %141
%151 = add <4 x i32> %149, %142
%152 = add nuw i64 %113, 32
%153 = add i64 %116, 4
%154 = icmp eq i64 %153, %111
br i1 %154, label %155, label %112
155: ; preds = %112, %103
%156 = phi <4 x i32> [ undef, %103 ], [ %150, %112 ]
%157 = phi <4 x i32> [ undef, %103 ], [ %151, %112 ]
%158 = phi i64 [ 0, %103 ], [ %152, %112 ]
%159 = phi <4 x i32> [ zeroinitializer, %103 ], [ %150, %112 ]
%160 = phi <4 x i32> [ zeroinitializer, %103 ], [ %151, %112 ]
%161 = icmp eq i64 %108, 0
br i1 %161, label %178, label %162
162: ; preds = %155, %162
%163 = phi i64 [ %175, %162 ], [ %158, %155 ]
%164 = phi <4 x i32> [ %173, %162 ], [ %159, %155 ]
%165 = phi <4 x i32> [ %174, %162 ], [ %160, %155 ]
%166 = phi i64 [ %176, %162 ], [ 0, %155 ]
%167 = getelementptr inbounds i32, i32* %86, i64 %163
%168 = bitcast i32* %167 to <4 x i32>*
%169 = load <4 x i32>, <4 x i32>* %168
%170 = getelementptr inbounds i32, i32* %167, i64 4
%171 = bitcast i32* %170 to <4 x i32>*
%172 = load <4 x i32>, <4 x i32>* %171
%173 = add <4 x i32> %169, %164
%174 = add <4 x i32> %172, %165
%175 = add nuw i64 %163, 8
%176 = add i64 %166, 1
%177 = icmp eq i64 %176, %108
br i1 %177, label %178, label %162
178: ; preds = %162, %155
%179 = phi <4 x i32> [ %156, %155 ], [ %173, %162 ]
%180 = phi <4 x i32> [ %157, %155 ], [ %174, %162 ]
%181 = add <4 x i32> %180, %179
%182 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %181)
%183 = icmp eq i64 %104, %101
br i1 %183, label %195, label %184
184: ; preds = %100, %178
%185 = phi i64 [ 0, %100 ], [ %104, %178 ]
%186 = phi i32 [ 0, %100 ], [ %182, %178 ]
br label %187
187: ; preds = %184, %187
%188 = phi i64 [ %193, %187 ], [ %185, %184 ]
%189 = phi i32 [ %192, %187 ], [ %186, %184 ]
%190 = getelementptr inbounds i32, i32* %86, i64 %188
%191 = load i32, i32* %190
%192 = add nsw i32 %191, %189
%193 = add nuw nsw i64 %188, 1
%194 = icmp eq i64 %193, %101
br i1 %194, label %195, label %187
195: ; preds = %187, %178, %84
%196 = phi i32 [ 0, %84 ], [ %182, %178 ], [ %192, %187 ]
%197 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %196)
%198 = call i32 @close(i32 %26)
%199 = load i32, i32* @EXIT_SUCCESS
br label %200
200: ; preds = %30, %74, %195, %14
%201 = phi i32 [ %18, %14 ], [ %32, %30 ], [ %75, %74 ], [ %199, %195 ]
ret i32 %201
}