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

/* Variables and functions */
int /*<<< orphan*/ pthread_join(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
int wait_and_kill(pthread_t *producer_threadID, int max_producer_thread,
                  pthread_t *consumer_threadID, int max_consumer_thread) {
  for (int i = 0; i < max_producer_thread; i++)
    pthread_join(producer_threadID[i], NULL);
  for (int i = 0; i < max_consumer_thread; i++)
    pthread_join(consumer_threadID[i], NULL);
  sleep(1);
}


x86 assembly (clang, -O0):
<wait_and_kill>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    116b <wait_and_kill+0x4b>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <pthread_join@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    113d <wait_and_kill+0x1d>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11a0 <wait_and_kill+0x80>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <pthread_join@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1172 <wait_and_kill+0x52>
mov    $0x1,%edi
call   1040 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_and_kill>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%r15
test   %esi,%esi
jle    1154 <wait_and_kill+0x34>
mov    %rdi,%r12
mov    %esi,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    (%r12,%rbp,4),%edi
xor    %esi,%esi
call   1030 <pthread_join@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1140 <wait_and_kill+0x20>
test   %r14d,%r14d
jle    1174 <wait_and_kill+0x54>
mov    %r14d,%ebx
xor    %ebp,%ebp
xchg   %ax,%ax
mov    (%r15,%rbp,4),%edi
xor    %esi,%esi
call   1030 <pthread_join@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <wait_and_kill+0x40>
mov    $0x1,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <sleep@plt>

LLVM IR (-O0):
define i32 @wait_and_kill(i32* %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32 %3, i32* %9
store i32 0, i32* %10
br label %12
12: ; preds = %23, %4
%13 = load i32, i32* %10
%14 = load i32, i32* %7
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = load i32*, i32** %6
%18 = load i32, i32* %10
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = call i32 @pthread_join(i32 %21, i32* null)
br label %23
23: ; preds = %16
%24 = load i32, i32* %10
%25 = add nsw i32 %24, 1
store i32 %25, i32* %10
br label %12
26: ; preds = %12
store i32 0, i32* %11
br label %27
27: ; preds = %38, %26
%28 = load i32, i32* %11
%29 = load i32, i32* %9
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %41
31: ; preds = %27
%32 = load i32*, i32** %8
%33 = load i32, i32* %11
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
%37 = call i32 @pthread_join(i32 %36, i32* null)
br label %38
38: ; preds = %31
%39 = load i32, i32* %11
%40 = add nsw i32 %39, 1
store i32 %40, i32* %11
br label %27
41: ; preds = %27
%42 = call i32 @sleep(i32 1)
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
define i32 @wait_and_kill(i32* nocapture %0, i32 %1, i32* nocapture %2, i32 %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = zext i32 %1 to i64
br label %12
8: ; preds = %12, %4
%9 = icmp sgt i32 %3, 0
br i1 %9, label %10, label %19
10: ; preds = %8
%11 = zext i32 %3 to i64
br label %21
12: ; preds = %6, %12
%13 = phi i64 [ 0, %6 ], [ %17, %12 ]
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = tail call i32 @pthread_join(i32 %15, i32* null)
%17 = add nuw nsw i64 %13, 1
%18 = icmp eq i64 %17, %7
br i1 %18, label %8, label %12
19: ; preds = %21, %8
%20 = tail call i32 @sleep(i32 1)
ret i32 undef
21: ; preds = %10, %21
%22 = phi i64 [ 0, %10 ], [ %26, %21 ]
%23 = getelementptr inbounds i32, i32* %2, i64 %22
%24 = load i32, i32* %23
%25 = tail call i32 @pthread_join(i32 %24, i32* null)
%26 = add nuw nsw i64 %22, 1
%27 = icmp eq i64 %26, %11
br i1 %27, label %19, label %21
}