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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int RAND_MAX;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ ftruncate(int, int);
int getpid();
int /*<<< orphan*/ *malloc(int);
int *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
          int /*<<< orphan*/);
int /*<<< orphan*/ munmap(int *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ rand();
int shm_open(char *, int, int);
int /*<<< orphan*/ shm_unlink(char *);
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int time(int /*<<< orphan*/ *);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/);
int main(int argc, char **argv) {
  int *addr_at;
  int shm_id, i, nb_proc, total;
  pid_t *pids;
  pid_t pid;
  if (argc != 2 || !strcmp(argv[1], "-h")) {
    fprintf(stderr, "usage: %s NB_THREADS\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  nb_proc = atoi(argv[1]);
  pids = malloc(nb_proc * sizeof(pid_t));
  total = 0;
  if ((shm_id = shm_open("posixshm", O_CREAT | O_RDWR, 0600)) == -1) {
    perror("can't open shared memory");
    exit(EXIT_FAILURE);
  }
  ftruncate(shm_id, nb_proc * sizeof(int));
  if ((addr_at = mmap(NULL, nb_proc * sizeof(int), PROT_READ | PROT_WRITE,
                      MAP_SHARED, shm_id, 0)) == MAP_FAILED) {
    perror("failed to mmap shared memory");
    exit(EXIT_FAILURE);
  }
  for (i = 0; i < nb_proc; i++) {
    if ((pid = fork()) == 0) {
      srand(time(NULL) ^ (getpid() << 16));
      addr_at[i] = (int)(10 * (float)rand() / RAND_MAX);
      exit(EXIT_SUCCESS);
    } else
      pids[i] = pid;
  }
  for (i = 0; i < nb_proc; i++)
    waitpid(pids[i], NULL, 0);
  for (i = 0; i < nb_proc; i++)
    total = total + addr_at[i];
  printf("total = %d\n", total);
  munmap(addr_at, nb_proc * sizeof(int));
  shm_unlink("posixshm");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    125d <main+0x3d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdb5(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1287 <main+0x67>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd93(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x28(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
mov    0x2d0f(%rip),%rax
or     (%rax),%esi
lea    0xd53(%rip),%rdi
mov    $0x180,%edx
call   1110 <shm_open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    12fa <main+0xda>
lea    0xd3f(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x1c(%rbp),%edi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1060 <ftruncate@plt>
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
mov    0x2cd3(%rip),%rax
mov    (%rax),%edx
mov    0x2c82(%rip),%rax
or     (%rax),%edx
mov    0x2cb1(%rip),%rax
mov    (%rax),%ecx
mov    -0x1c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    0x2c4c(%rip),%rcx
cmp    (%rcx),%rax
jne    136f <main+0x14f>
lea    0xce3(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c48(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    141a <main+0x1fa>
mov    $0x0,%al
call   1130 <fork@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jne    13f9 <main+0x1d9>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x38(%rbp),%edi
shl    $0x10,%eax
xor    %eax,%edi
call   1070 <srand@plt>
mov    $0x0,%al
call   1140 <rand@plt>
cvtsi2ss %rax,%xmm1
movss  0xc37(%rip),%xmm0
mulss  %xmm1,%xmm0
mov    0x2bf4(%rip),%rax
cvtsi2ssl (%rax),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%edx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    0x2bae(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    140c <main+0x1ec>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1376 <main+0x156>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1451 <main+0x231>
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1421 <main+0x201>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1483 <main+0x263>
mov    -0x28(%rbp),%eax
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
add    (%rcx,%rdx,4),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1458 <main+0x238>
mov    -0x28(%rbp),%esi
lea    0xbcf(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   10c0 <munmap@plt>
lea    0xb71(%rip),%rdi
call   1120 <shm_unlink@plt>
mov    0x2ae8(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    124a <main+0x2a>
mov    0x8(%rbx),%rbp
lea    0xdc6(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
jne    1267 <main+0x47>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdaa(%rip),%rsi
call   1090 <fprintf@plt>
jmp    130b <main+0xeb>
mov    %rbp,%rdi
call   10f0 <atoi@plt>
mov    %eax,%r15d
lea    0x0(,%r15,4),%r14d
mov    %r14d,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbp
mov    0x2d6c(%rip),%rax
mov    0x2d3d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xd7f(%rip),%rdi
mov    $0x180,%edx
call   1110 <shm_open@plt>
cmp    $0xffffffff,%eax
jne    12b6 <main+0x96>
lea    0xd72(%rip),%rdi
jmp    1306 <main+0xe6>
mov    %eax,%r12d
mov    %eax,%edi
mov    %r14d,%esi
call   1060 <ftruncate@plt>
mov    0x2d26(%rip),%rax
mov    0x2cd7(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d04(%rip),%rax
mov    (%rax),%ecx
xor    %ebx,%ebx
xor    %edi,%edi
mov    %r14d,%esi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%r12
mov    0x2c9e(%rip),%rax
cmp    (%rax),%r12
jne    1319 <main+0xf9>
lea    0xd39(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
test   %r15d,%r15d
jle    14ed <main+0x2cd>
mov    %r15d,%r13d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1130 <fork@plt>
test   %eax,%eax
je     1390 <main+0x170>
mov    %eax,0x0(%rbp,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1330 <main+0x110>
xor    %ebx,%ebx
test   %r15d,%r15d
jle    14ed <main+0x2cd>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%rbp,%rbx,4),%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1360 <main+0x140>
xor    %ebx,%ebx
test   %r15d,%r15d
jle    14ed <main+0x2cd>
cmp    $0x8,%r15d
jae    13dc <main+0x1bc>
xor    %eax,%eax
xor    %ebx,%ebx
jmp    14e0 <main+0x2c0>
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
shl    $0x10,%eax
xor    %eax,%ebp
mov    %ebp,%edi
call   1070 <srand@plt>
xor    %eax,%eax
call   1140 <rand@plt>
cvtsi2ss %rax,%xmm0
mulss  0xc40(%rip),%xmm0
mov    0x2c01(%rip),%rax
cvtsi2ssl (%rax),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,(%r12,%rbx,4)
jmp    1512 <main+0x2f2>
mov    %r13d,%eax
and    $0xfffffff8,%eax
lea    -0x8(%rax),%rdx
mov    %rdx,%rsi
shr    $0x3,%rsi
add    $0x1,%rsi
mov    %esi,%ecx
and    $0x3,%ecx
cmp    $0x18,%rdx
jae    1408 <main+0x1e8>
pxor   %xmm0,%xmm0
xor    %edx,%edx
pxor   %xmm1,%xmm1
jmp    1481 <main+0x261>
and    $0xfffffffffffffffc,%rsi
pxor   %xmm0,%xmm0
xor    %edx,%edx
pxor   %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
movdqu (%r12,%rdx,4),%xmm2
paddd  %xmm0,%xmm2
movdqu 0x10(%r12,%rdx,4),%xmm0
paddd  %xmm1,%xmm0
movdqu 0x20(%r12,%rdx,4),%xmm1
movdqu 0x30(%r12,%rdx,4),%xmm3
movdqu 0x40(%r12,%rdx,4),%xmm4
paddd  %xmm1,%xmm4
paddd  %xmm2,%xmm4
movdqu 0x50(%r12,%rdx,4),%xmm2
paddd  %xmm3,%xmm2
paddd  %xmm0,%xmm2
movdqu 0x60(%r12,%rdx,4),%xmm0
paddd  %xmm4,%xmm0
movdqu 0x70(%r12,%rdx,4),%xmm1
paddd  %xmm2,%xmm1
add    $0x20,%rdx
add    $0xfffffffffffffffc,%rsi
jne    1420 <main+0x200>
test   %rcx,%rcx
je     14bc <main+0x29c>
lea    (%r12,%rdx,4),%rdx
add    $0x10,%rdx
shl    $0x5,%rcx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movdqu -0x10(%rdx,%rsi,1),%xmm2
paddd  %xmm2,%xmm0
movdqu (%rdx,%rsi,1),%xmm2
paddd  %xmm2,%xmm1
add    $0x20,%rsi
cmp    %rsi,%rcx
jne    14a0 <main+0x280>
paddd  %xmm1,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%ebx
cmp    %r13,%rax
je     14ed <main+0x2cd>
nopl   0x0(%rax,%rax,1)
add    (%r12,%rax,4),%ebx
add    $0x1,%rax
cmp    %rax,%r13
jne    14e0 <main+0x2c0>
lea    0xb68(%rip),%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r14d,%esi
call   10c0 <munmap@plt>
lea    0xb10(%rip),%rdi
call   1120 <shm_unlink@plt>
mov    0x2a87(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.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 = [9 x i8] c"posixshm\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.3 = [25 x i8] c"can't open shared memory\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i32* null
@.str.4 = [29 x i8] c"failed to mmap shared memory\00"
@RAND_MAX = global i32 0
@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 i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %21, label %15
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %15, %2
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %15
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %9
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = mul i64 %35, 4
%37 = trunc i64 %36 to i32
%38 = call i32* @malloc(i32 %37)
store i32* %38, i32** %11
store i32 0, i32* %10
%39 = load i32, i32* @O_CREAT
%40 = load i32, i32* @O_RDWR
%41 = or i32 %39, %40
%42 = call i32 @shm_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %41, i32 384)
store i32 %42, i32* %7
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %48
44: ; preds = %29
%45 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %29
%49 = load i32, i32* %7
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = mul i64 %51, 4
%53 = trunc i64 %52 to i32
%54 = call i32 @ftruncate(i32 %49, i32 %53)
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = mul i64 %56, 4
%58 = trunc i64 %57 to i32
%59 = load i32, i32* @PROT_READ
%60 = load i32, i32* @PROT_WRITE
%61 = or i32 %59, %60
%62 = load i32, i32* @MAP_SHARED
%63 = load i32, i32* %7
%64 = call i32* @mmap(i32* null, i32 %58, i32 %61, i32 %62, i32 %63, i32 0)
store i32* %64, i32** %6
%65 = load i32*, i32** @MAP_FAILED
%66 = icmp eq i32* %64, %65
br i1 %66, label %67, label %71
67: ; preds = %48
%68 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %48
store i32 0, i32* %8
br label %72
72: ; preds = %105, %71
%73 = load i32, i32* %8
%74 = load i32, i32* %9
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %108
76: ; preds = %72
%77 = call i32 (...) @fork()
store i32 %77, i32* %12
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %98
79: ; preds = %76
%80 = call i32 @time(i32* null)
%81 = call i32 (...) @getpid()
%82 = shl i32 %81, 16
%83 = xor i32 %80, %82
%84 = call i32 @srand(i32 %83)
%85 = call i64 (...) @rand()
%86 = sitofp i64 %85 to float
%87 = fmul float 1.000000e+01, %86
%88 = load i32, i32* @RAND_MAX
%89 = sitofp i32 %88 to float
%90 = fdiv float %87, %89
%91 = fptosi float %90 to i32
%92 = load i32*, i32** %6
%93 = load i32, i32* %8
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i32, i32* %92, i64 %94
store i32 %91, i32* %95
%96 = load i32, i32* @EXIT_SUCCESS
%97 = call i32 @exit(i32 %96)
unreachable
98: ; preds = %76
%99 = load i32, i32* %12
%100 = load i32*, i32** %11
%101 = load i32, i32* %8
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i32, i32* %100, i64 %102
store i32 %99, i32* %103
br label %104
104: ; preds = %98
br label %105
105: ; preds = %104
%106 = load i32, i32* %8
%107 = add nsw i32 %106, 1
store i32 %107, i32* %8
br label %72
108: ; preds = %72
store i32 0, i32* %8
br label %109
109: ; preds = %120, %108
%110 = load i32, i32* %8
%111 = load i32, i32* %9
%112 = icmp slt i32 %110, %111
br i1 %112, label %113, label %123
113: ; preds = %109
%114 = load i32*, i32** %11
%115 = load i32, i32* %8
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i32, i32* %114, i64 %116
%118 = load i32, i32* %117
%119 = call i32 @waitpid(i32 %118, i32* null, i32 0)
br label %120
120: ; preds = %113
%121 = load i32, i32* %8
%122 = add nsw i32 %121, 1
store i32 %122, i32* %8
br label %109
123: ; preds = %109
store i32 0, i32* %8
br label %124
124: ; preds = %136, %123
%125 = load i32, i32* %8
%126 = load i32, i32* %9
%127 = icmp slt i32 %125, %126
br i1 %127, label %128, label %139
128: ; preds = %124
%129 = load i32, i32* %10
%130 = load i32*, i32** %6
%131 = load i32, i32* %8
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds i32, i32* %130, i64 %132
%134 = load i32, i32* %133
%135 = add nsw i32 %129, %134
store i32 %135, i32* %10
br label %136
136: ; preds = %128
%137 = load i32, i32* %8
%138 = add nsw i32 %137, 1
store i32 %138, i32* %8
br label %124
139: ; preds = %124
%140 = load i32, i32* %10
%141 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %140)
%142 = load i32*, i32** %6
%143 = load i32, i32* %9
%144 = sext i32 %143 to i64
%145 = mul i64 %144, 4
%146 = trunc i64 %145 to i32
%147 = call i32 @munmap(i32* %142, i32 %146)
%148 = call i32 @shm_unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%149 = load i32, i32* @EXIT_SUCCESS
%150 = call i32 @exit(i32 %149)
unreachable
}

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