#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 */
int /*<<< orphan*/ find_prime_numbers(int, int, int);
int /*<<< orphan*/ free(void *);
scalar_t__ is_even(int);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
void *produce(void *params) {
  int *parameters = params;
  int start = *parameters;
  int end = *(parameters + 1);
  int thread_number = *(parameters + 2);
  printf("Thread number: %d\tRange: [%d:%d]\n", thread_number, start, end);
  if (is_even(start)) {
    if (is_even(end)) {
      find_prime_numbers(start + 1, end - 1, thread_number);
    } else {
      find_prime_numbers(start + 1, end, thread_number);
    }
  } else {
    if (is_even(end)) {
      find_prime_numbers(start, end - 1, thread_number);
    } else {
      find_prime_numbers(start, end, thread_number);
    }
  }
  printf("Producer Thread %d has finished\n", thread_number);
  free(params);
  pthread_exit(NULL);
  return NULL;
}


x86 assembly (clang, -O0):
<produce>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <is_even@plt>
cmp    $0x0,%rax
je     11eb <produce+0x9b>
mov    -0x18(%rbp),%edi
call   1050 <is_even@plt>
cmp    $0x0,%rax
je     11d5 <produce+0x85>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
mov    -0x18(%rbp),%esi
sub    $0x1,%esi
mov    -0x1c(%rbp),%edx
call   1070 <find_prime_numbers@plt>
jmp    11e6 <produce+0x96>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1070 <find_prime_numbers@plt>
jmp    1226 <produce+0xd6>
mov    -0x18(%rbp),%edi
call   1050 <is_even@plt>
cmp    $0x0,%rax
je     1213 <produce+0xc3>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
sub    $0x1,%esi
mov    -0x1c(%rbp),%edx
call   1070 <find_prime_numbers@plt>
jmp    1221 <produce+0xd1>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1070 <find_prime_numbers@plt>
jmp    1226 <produce+0xd6>
mov    -0x1c(%rbp),%esi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <pthread_exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<produce>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
mov    (%rdi),%ebx
mov    0x4(%rdi),%ebp
mov    0x8(%rdi),%r14d
lea    0xe95(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <is_even@plt>
mov    %rax,%r12
mov    %ebp,%edi
call   1050 <is_even@plt>
test   %r12,%r12
je     1192 <produce+0x42>
add    $0x1,%ebx
test   %rax,%rax
je     119a <produce+0x4a>
add    $0xffffffff,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r14d,%edx
call   1070 <find_prime_numbers@plt>
lea    0xe75(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1060 <pthread_exit@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Thread number: %d\09Range: [%d:%d]\0A\00"
@.str.1 = [33 x i8] c"Producer Thread %d has finished\0A\00"
define i8* @produce(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = bitcast i8* %7 to i32*
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = load i32, i32* %9
store i32 %10, i32* %4
%11 = load i32*, i32** %3
%12 = getelementptr inbounds i32, i32* %11, i64 1
%13 = load i32, i32* %12
store i32 %13, i32* %5
%14 = load i32*, i32** %3
%15 = getelementptr inbounds i32, i32* %14, i64 2
%16 = load i32, i32* %15
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18, i32 %19)
%21 = load i32, i32* %4
%22 = call i64 @is_even(i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %42
24: ; preds = %1
%25 = load i32, i32* %5
%26 = call i64 @is_even(i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %24
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
%31 = load i32, i32* %5
%32 = sub nsw i32 %31, 1
%33 = load i32, i32* %6
%34 = call i32 @find_prime_numbers(i32 %30, i32 %32, i32 %33)
br label %41
35: ; preds = %24
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
%38 = load i32, i32* %5
%39 = load i32, i32* %6
%40 = call i32 @find_prime_numbers(i32 %37, i32 %38, i32 %39)
br label %41
41: ; preds = %35, %28
br label %58
42: ; preds = %1
%43 = load i32, i32* %5
%44 = call i64 @is_even(i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = load i32, i32* %4
%48 = load i32, i32* %5
%49 = sub nsw i32 %48, 1
%50 = load i32, i32* %6
%51 = call i32 @find_prime_numbers(i32 %47, i32 %49, i32 %50)
br label %57
52: ; preds = %42
%53 = load i32, i32* %4
%54 = load i32, i32* %5
%55 = load i32, i32* %6
%56 = call i32 @find_prime_numbers(i32 %53, i32 %54, i32 %55)
br label %57
57: ; preds = %52, %46
br label %58
58: ; preds = %57, %41
%59 = load i32, i32* %6
%60 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %59)
%61 = load i8*, i8** %2
%62 = call i32 @free(i8* %61)
%63 = call i32 @pthread_exit(i32* null)
ret i8* null
}

LLVM IR (-O2):
@.str = [34 x i8] c"Thread number: %d\09Range: [%d:%d]\0A\00"
@.str.1 = [33 x i8] c"Producer Thread %d has finished\0A\00"
define noalias i8* @produce(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
%4 = getelementptr inbounds i8, i8* %0, i64 4
%5 = bitcast i8* %4 to i32*
%6 = load i32, i32* %5
%7 = getelementptr inbounds i8, i8* %0, i64 8
%8 = bitcast i8* %7 to i32*
%9 = load i32, i32* %8
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %3, i32 %6)
%11 = tail call i64 @is_even(i32 %3)
%12 = icmp eq i64 %11, 0
%13 = tail call i64 @is_even(i32 %6)
%14 = icmp eq i64 %13, 0
br i1 %12, label %22, label %15
15: ; preds = %1
%16 = add nsw i32 %3, 1
br i1 %14, label %20, label %17
17: ; preds = %15
%18 = add nsw i32 %6, -1
%19 = tail call i32 @find_prime_numbers(i32 %16, i32 %18, i32 %9)
br label %28
20: ; preds = %15
%21 = tail call i32 @find_prime_numbers(i32 %16, i32 %6, i32 %9)
br label %28
22: ; preds = %1
br i1 %14, label %26, label %23
23: ; preds = %22
%24 = add nsw i32 %6, -1
%25 = tail call i32 @find_prime_numbers(i32 %3, i32 %24, i32 %9)
br label %28
26: ; preds = %22
%27 = tail call i32 @find_prime_numbers(i32 %3, i32 %6, i32 %9)
br label %28
28: ; preds = %23, %26, %17, %20
%29 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%30 = tail call i32 @free(i8* %0)
%31 = tail call i32 @pthread_exit(i32* null)
ret i8* null
}