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

/* Variables and functions */
scalar_t__ malloc(int);
int omp_get_thread_num();
int /*<<< orphan*/ printf(char *, ...);
int strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  int thread_count, iterations, i, j;
  int *assignments;
  int my_rank;
  int a[10];
  thread_count = strtol(argv[1], NULL, 10);
  iterations = strtol(argv[2], NULL, 10);
  assignments = (int *)malloc(iterations * sizeof(int));
  a[0] = 0;
#pragma omp parallel for num_threads(thread_count)
  for (i = 1; i < 10; i++) {
    a[i] = a[i - 1] + i;
  }
#pragma omp parallel for num_threads(thread_count)
  for (i = 0; i < iterations; i++) {
    my_rank = omp_get_thread_num();
    assignments[i] = my_rank;
  }
  for (i = 0; i < thread_count; i++) {
    printf("Thread %d: Iterations ", i);
    for (j = 0; j < iterations; j++) {
      if (assignments[j] == i) {
        printf("%d ", j);
      }
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x60(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    11d8 <main+0x98>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x60(%rbp,%rax,4),%ecx
add    -0x1c(%rbp),%ecx
movslq -0x1c(%rbp),%rax
mov    %ecx,-0x60(%rbp,%rax,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a9 <main+0x69>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1211 <main+0xd1>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11df <main+0x9f>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    129c <main+0x15c>
mov    -0x1c(%rbp),%esi
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1280 <main+0x140>
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x1c(%rbp),%eax
jne    126d <main+0x12d>
mov    -0x20(%rbp),%esi
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1272 <main+0x132>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    123c <main+0xfc>
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1218 <main+0xd8>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,0x4(%rsp)
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%r12d
lea    0x0(,%r12,4),%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    %r12d,%r14d
test   %r12d,%r12d
jle    11b4 <main+0x64>
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %eax,0x0(%rbp,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11a0 <main+0x50>
cmpl   $0x0,0x4(%rsp)
jle    121f <main+0xcf>
lea    0xe55(%rip),%r13
xor    %ebx,%ebx
jmp    11e3 <main+0x93>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
cmp    0x4(%rsp),%ebx
je     121f <main+0xcf>
lea    0xe16(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r12d,%r12d
jle    11d0 <main+0x80>
xor    %r15d,%r15d
jmp    1209 <main+0xb9>
nopl   (%rax)
add    $0x1,%r15
cmp    %r15,%r14
je     11d0 <main+0x80>
cmp    %ebx,0x0(%rbp,%r15,4)
jne    1200 <main+0xb0>
mov    %r13,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1200 <main+0xb0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Thread %d: Iterations \00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [2 x i8] c"\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 [10 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @strtol(i8* %15, i32* null, i32 10)
store i32 %16, i32* %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @strtol(i8* %19, i32* null, i32 10)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 4
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i32*
store i32* %26, i32** %10
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %12, i64 0, i64 0
store i32 0, i32* %27
store i32 1, i32* %8
br label %28
28: ; preds = %42, %2
%29 = load i32, i32* %8
%30 = icmp slt i32 %29, 10
br i1 %30, label %31, label %45
31: ; preds = %28
%32 = load i32, i32* %8
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [10 x i32], [10 x i32]* %12, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = load i32, i32* %8
%38 = add nsw i32 %36, %37
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [10 x i32], [10 x i32]* %12, i64 0, i64 %40
store i32 %38, i32* %41
br label %42
42: ; preds = %31
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %28
45: ; preds = %28
store i32 0, i32* %8
br label %46
46: ; preds = %57, %45
%47 = load i32, i32* %8
%48 = load i32, i32* %7
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %60
50: ; preds = %46
%51 = call i32 (...) @omp_get_thread_num()
store i32 %51, i32* %11
%52 = load i32, i32* %11
%53 = load i32*, i32** %10
%54 = load i32, i32* %8
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
store i32 %52, i32* %56
br label %57
57: ; preds = %50
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
store i32 %59, i32* %8
br label %46
60: ; preds = %46
store i32 0, i32* %8
br label %61
61: ; preds = %89, %60
%62 = load i32, i32* %8
%63 = load i32, i32* %6
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %92
65: ; preds = %61
%66 = load i32, i32* %8
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %66)
store i32 0, i32* %9
br label %68
68: ; preds = %84, %65
%69 = load i32, i32* %9
%70 = load i32, i32* %7
%71 = icmp slt i32 %69, %70
br i1 %71, label %72, label %87
72: ; preds = %68
%73 = load i32*, i32** %10
%74 = load i32, i32* %9
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i32, i32* %73, i64 %75
%77 = load i32, i32* %76
%78 = load i32, i32* %8
%79 = icmp eq i32 %77, %78
br i1 %79, label %80, label %83
80: ; preds = %72
%81 = load i32, i32* %9
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %81)
br label %83
83: ; preds = %80, %72
br label %84
84: ; preds = %83
%85 = load i32, i32* %9
%86 = add nsw i32 %85, 1
store i32 %86, i32* %9
br label %68
87: ; preds = %68
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %89
89: ; preds = %87
%90 = load i32, i32* %8
%91 = add nsw i32 %90, 1
store i32 %91, i32* %8
br label %61
92: ; preds = %61
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"Thread %d: Iterations \00"
@.str.1 = [4 x i8] c"%d \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @strtol(i8* nocapture %4, i32* null, i32 10)
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = tail call i32 @strtol(i8* nocapture %7, i32* null, i32 10)
%9 = shl i32 %8, 2
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i32*
%12 = icmp sgt i32 %8, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = zext i32 %8 to i64
br label %19
15: ; preds = %19, %2
%16 = icmp sgt i32 %5, 0
br i1 %16, label %17, label %43
17: ; preds = %15
%18 = zext i32 %8 to i64
br label %25
19: ; preds = %13, %19
%20 = phi i64 [ 0, %13 ], [ %23, %19 ]
%21 = tail call i32 (...) @omp_get_thread_num()
%22 = getelementptr inbounds i32, i32* %11, i64 %20
store i32 %21, i32* %22
%23 = add nuw nsw i64 %20, 1
%24 = icmp eq i64 %23, %14
br i1 %24, label %15, label %19
25: ; preds = %17, %39
%26 = phi i32 [ 0, %17 ], [ %41, %39 ]
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %26)
br i1 %12, label %28, label %39
28: ; preds = %25, %36
%29 = phi i64 [ %37, %36 ], [ 0, %25 ]
%30 = getelementptr inbounds i32, i32* %11, i64 %29
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, %26
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = trunc i64 %29 to i32
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %28, %33
%37 = add nuw nsw i64 %29, 1
%38 = icmp eq i64 %37, %18
br i1 %38, label %39, label %28
39: ; preds = %36, %25
%40 = tail call i32 @putchar(i32 10)
%41 = add nuw nsw i32 %26, 1
%42 = icmp eq i32 %41, %5
br i1 %42, label %43, label %25
43: ; preds = %39, %15
ret i32 0
}