#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 */
struct node {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getopt(int, char **, char *);
struct node *make_list(long);
int omp_get_max_threads();
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ print_list(struct node *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ process_list(struct node *);
int /*<<< orphan*/ srand(int const);
void *strtol(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  const int seed = 1234;
  srand(seed);
  long list_size = 1000;
  int max_threads = omp_get_max_threads();
  int num_threads = 1;
  int nodes_to_print = 10;
  int opt;
  while ((opt = getopt(argc, argv, "p:s:t:")) != -1) {
    switch (opt) {
    case 'p':
      nodes_to_print = strtol(optarg, NULL, 10);
      break;
    case 's':
      list_size = strtol(optarg, NULL, 10);
      break;
    case 't':
      num_threads = strtol(optarg, NULL, 10);
      break;
    default:
      printf("usage: %s -p <nodes_to_print> -s <list_size> -t <num_threads>\n",
             argv[0]);
    }
  }
  omp_set_num_threads(num_threads);
  printf("// list_size = %ld, num_threads = %d, max_threads = %d\n", list_size,
         num_threads, max_threads);
  struct node *first = make_list(list_size);
  print_list(first, nodes_to_print);
  printf("// processing...\n");
  process_list(first);
  print_list(first, nodes_to_print);
  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)
movl   $0x4d2,-0x14(%rbp)
mov    $0x4d2,%edi
call   1060 <srand@plt>
movq   $0x3e8,-0x20(%rbp)
mov    $0x0,%al
call   10a0 <omp_get_max_threads@plt>
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
movl   $0xa,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe0b(%rip),%rdx
call   10b0 <getopt@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
je     12b4 <main+0x114>
mov    -0x30(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x70,%eax
je     123c <main+0x9c>
jmp    121a <main+0x7a>
mov    -0x3c(%rbp),%eax
sub    $0x73,%eax
je     125b <main+0xbb>
jmp    122b <main+0x8b>
mov    -0x3c(%rbp),%eax
sub    $0x74,%eax
je     127b <main+0xdb>
jmp    129a <main+0xfa>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,-0x2c(%rbp)
jmp    12af <main+0x10f>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x20(%rbp)
jmp    12af <main+0x10f>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,-0x28(%rbp)
jmp    12af <main+0x10f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e7 <main+0x47>
mov    -0x28(%rbp),%edi
call   1090 <omp_set_num_threads@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <make_list@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1030 <print_list@plt>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1080 <process_list@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1030 <print_list@plt>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x4d2,%edi
call   1070 <srand@plt>
xor    %eax,%eax
call   10b0 <omp_get_max_threads@plt>
mov    %eax,0x4(%rsp)
mov    $0x3e8,%eax
mov    %rax,0x8(%rsp)
mov    $0x1,%r13d
mov    $0xa,%eax
mov    %rax,0x10(%rsp)
lea    0xe07(%rip),%r15
mov    0x2df8(%rip),%r12
lea    0xe00(%rip),%r14
jmp    1227 <main+0x77>
nopl   0x0(%rax)
cmp    $0x70,%eax
je     1258 <main+0xa8>
cmp    $0xffffffff,%eax
je     1286 <main+0xd6>
mov    (%rbx),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   10c0 <getopt@plt>
cmp    $0x72,%eax
jle    1210 <main+0x60>
cmp    $0x73,%eax
je     126f <main+0xbf>
cmp    $0x74,%eax
jne    121a <main+0x6a>
mov    (%r12),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %rax,%r13
jmp    1227 <main+0x77>
mov    (%r12),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %rax,0x10(%rsp)
jmp    1227 <main+0x77>
mov    (%r12),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %rax,0x8(%rsp)
jmp    1227 <main+0x77>
mov    %r13,%rbx
mov    %ebx,%edi
call   10a0 <omp_set_num_threads@plt>
lea    0xdaf(%rip),%rdi
mov    0x8(%rsp),%r13
mov    %r13,%rsi
mov    %ebx,%edx
mov    0x4(%rsp),%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
call   1060 <make_list@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    0x10(%rsp),%rbp
mov    %ebp,%esi
call   1040 <print_list@plt>
lea    0xdb1(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1090 <process_list@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <print_list@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [7 x i8] c"p:s:t:\00"
@optarg = global i32 0
@.str.1 = [63 x i8] c"usage: %s -p <nodes_to_print> -s <list_size> -t <num_threads>\0A\00"
@.str.2 = [56 x i8] c"// list_size = %ld, num_threads = %d, max_threads = %d\0A\00"
@.str.3 = [18 x i8] c"// processing...\0A\00"
@EXIT_SUCCESS = global i32 0
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 %struct.node*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1234, i32* %6
%13 = call i32 @srand(i32 1234)
store i64 1000, i64* %7
%14 = call i32 (...) @omp_get_max_threads()
store i32 %14, i32* %8
store i32 1, i32* %9
store i32 10, i32* %10
br label %15
15: ; preds = %39, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %11
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %40
20: ; preds = %15
%21 = load i32, i32* %11
switch i32 %21, label %34 [
i32 112, label %22
i32 115, label %26
i32 116, label %30
]
22: ; preds = %20
%23 = load i32, i32* @optarg
%24 = call i8* @strtol(i32 %23, i32* null, i32 10)
%25 = ptrtoint i8* %24 to i32
store i32 %25, i32* %10
br label %39
26: ; preds = %20
%27 = load i32, i32* @optarg
%28 = call i8* @strtol(i32 %27, i32* null, i32 10)
%29 = ptrtoint i8* %28 to i64
store i64 %29, i64* %7
br label %39
30: ; preds = %20
%31 = load i32, i32* @optarg
%32 = call i8* @strtol(i32 %31, i32* null, i32 10)
%33 = ptrtoint i8* %32 to i32
store i32 %33, i32* %9
br label %39
34: ; preds = %20
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %34, %30, %26, %22
br label %15
40: ; preds = %15
%41 = load i32, i32* %9
%42 = call i32 @omp_set_num_threads(i32 %41)
%43 = load i64, i64* %7
%44 = load i32, i32* %9
%45 = load i32, i32* %8
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i64 %43, i32 %44, i32 %45)
%47 = load i64, i64* %7
%48 = call %struct.node* @make_list(i64 %47)
store %struct.node* %48, %struct.node** %12
%49 = load %struct.node*, %struct.node** %12
%50 = load i32, i32* %10
%51 = call i32 @print_list(%struct.node* %49, i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%53 = load %struct.node*, %struct.node** %12
%54 = call i32 @process_list(%struct.node* %53)
%55 = load %struct.node*, %struct.node** %12
%56 = load i32, i32* %10
%57 = call i32 @print_list(%struct.node* %55, i32 %56)
%58 = load i32, i32* @EXIT_SUCCESS
%59 = call i32 @exit(i32 %58)
unreachable
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str = [7 x i8] c"p:s:t:\00"
@optarg = global i32 0
@.str.1 = [63 x i8] c"usage: %s -p <nodes_to_print> -s <list_size> -t <num_threads>\0A\00"
@.str.2 = [56 x i8] c"// list_size = %ld, num_threads = %d, max_threads = %d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [17 x i8] c"// processing...\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @srand(i32 1234)
%4 = tail call i32 (...) @omp_get_max_threads()
br label %5
5: ; preds = %16, %2
%6 = phi i32 [ %20, %16 ], [ 10, %2 ]
%7 = phi i32 [ %10, %16 ], [ 1, %2 ]
%8 = phi i64 [ %13, %16 ], [ 1000, %2 ]
br label %9
9: ; preds = %5, %25
%10 = phi i32 [ %7, %5 ], [ %29, %25 ]
%11 = phi i64 [ %8, %5 ], [ %13, %25 ]
br label %12
12: ; preds = %9, %21
%13 = phi i64 [ %11, %9 ], [ %24, %21 ]
br label %14
14: ; preds = %12, %30
%15 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
switch i32 %15, label %30 [
i32 -1, label %33
i32 112, label %16
i32 115, label %21
i32 116, label %25
]
16: ; preds = %14
%17 = load i32, i32* @optarg
%18 = tail call i8* @strtol(i32 %17, i32* null, i32 10)
%19 = ptrtoint i8* %18 to i64
%20 = trunc i64 %19 to i32
br label %5
21: ; preds = %14
%22 = load i32, i32* @optarg
%23 = tail call i8* @strtol(i32 %22, i32* null, i32 10)
%24 = ptrtoint i8* %23 to i64
br label %12
25: ; preds = %14
%26 = load i32, i32* @optarg
%27 = tail call i8* @strtol(i32 %26, i32* null, i32 10)
%28 = ptrtoint i8* %27 to i64
%29 = trunc i64 %28 to i32
br label %9
30: ; preds = %14
%31 = load i8*, i8** %1
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %14
33: ; preds = %14
%34 = tail call i32 @omp_set_num_threads(i32 %10)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i64 %13, i32 %10, i32 %4)
%36 = tail call %struct.node* @make_list(i64 %13)
%37 = tail call i32 @print_list(%struct.node* %36, i32 %6)
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%39 = tail call i32 @process_list(%struct.node* %36)
%40 = tail call i32 @print_list(%struct.node* %36, i32 %6)
%41 = load i32, i32* @EXIT_SUCCESS
%42 = tail call i32 @exit(i32 %41)
unreachable
}