#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;
  thread_count = strtol(argv[1], NULL, 10);
  iterations = strtol(argv[2], NULL, 10);
  assignments = (int *)malloc(iterations * sizeof(int));
#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    $0x30,%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,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11d4 <main+0x94>
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    11a2 <main+0x62>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    125f <main+0x11f>
mov    -0x1c(%rbp),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1243 <main+0x103>
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x1c(%rbp),%eax
jne    1230 <main+0xf0>
mov    -0x20(%rbp),%esi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1235 <main+0xf5>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11ff <main+0xbf>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11db <main+0x9b>
xor    %eax,%eax
add    $0x30,%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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @strtol(i8* %14, i32* null, i32 10)
store i32 %15, i32* %6
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @strtol(i8* %18, i32* null, i32 10)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 4
%23 = trunc i64 %22 to i32
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i32*
store i32* %25, i32** %10
store i32 0, i32* %8
br label %26
26: ; preds = %37, %2
%27 = load i32, i32* %8
%28 = load i32, i32* %7
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %40
30: ; preds = %26
%31 = call i32 (...) @omp_get_thread_num()
store i32 %31, i32* %11
%32 = load i32, i32* %11
%33 = load i32*, i32** %10
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
store i32 %32, i32* %36
br label %37
37: ; preds = %30
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %26
40: ; preds = %26
store i32 0, i32* %8
br label %41
41: ; preds = %69, %40
%42 = load i32, i32* %8
%43 = load i32, i32* %6
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %72
45: ; preds = %41
%46 = load i32, i32* %8
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %46)
store i32 0, i32* %9
br label %48
48: ; preds = %64, %45
%49 = load i32, i32* %9
%50 = load i32, i32* %7
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %67
52: ; preds = %48
%53 = load i32*, i32** %10
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
%57 = load i32, i32* %56
%58 = load i32, i32* %8
%59 = icmp eq i32 %57, %58
br i1 %59, label %60, label %63
60: ; preds = %52
%61 = load i32, i32* %9
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %60, %52
br label %64
64: ; preds = %63
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
br label %48
67: ; preds = %48
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %69
69: ; preds = %67
%70 = load i32, i32* %8
%71 = add nsw i32 %70, 1
store i32 %71, i32* %8
br label %41
72: ; preds = %41
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
}