#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 errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int pthread_cancel(int /*<<< orphan*/);
int /*<<< orphan*/ pthread_join(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void terminateThreads(pthread_t *threads, int num_threads) {
  int i;
  for (i = 0; i < num_threads; i++) {
    if (pthread_cancel(threads[i]) == -1) {
      do {
        if (1) {
          fprintf(stderr, "%s: %d: ",
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/CRUx-BPHC/crux-judge/refs/"
                  "heads/development/src/server/contest/sandbox/terminate.c",
                  153);
          fprintf(stderr, "pthread_cancel failed: errno: %d", errno);
          fprintf(stderr, "\n");
        }
      } while (0);
    }
  }
  for (i = 0; i < num_threads; i++) {
    pthread_join(threads[i], NULL);
  }
}


x86 assembly (clang, -O0):
<terminateThreads>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e2 <terminateThreads+0xb2>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1050 <pthread_cancel@plt>
cmp    $0xffffffff,%eax
jne    11cf <terminateThreads+0x9f>
jmp    1170 <terminateThreads+0x40>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
lea    0xe82(%rip),%rdx
mov    $0x99,%ecx
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
lea    0xf0a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xf14(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11cf <terminateThreads+0x9f>
jmp    11d4 <terminateThreads+0xa4>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1146 <terminateThreads+0x16>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1217 <terminateThreads+0xe7>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <pthread_join@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e9 <terminateThreads+0xb9>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<terminateThreads>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11f3 <terminateThreads+0xc3>
mov    %rdi,%rbx
mov    %esi,0x4(%rsp)
mov    %esi,%r14d
mov    0x2e8c(%rip),%r15
lea    0xf5b(%rip),%r13
lea    0xf75(%rip),%rbp
xor    %r12d,%r12d
jmp    1179 <terminateThreads+0x49>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    %r12,%r14
je     11c9 <terminateThreads+0x99>
mov    (%rbx,%r12,4),%edi
call   1050 <pthread_cancel@plt>
cmp    $0xffffffff,%eax
jne    1170 <terminateThreads+0x40>
mov    (%r15),%edi
lea    0xe6f(%rip),%rsi
lea    0xe71(%rip),%rdx
mov    $0x99,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r15),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r15),%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1170 <terminateThreads+0x40>
cmpl   $0x0,0x4(%rsp)
jle    11f3 <terminateThreads+0xc3>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rbx,%rbp,4),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    11e0 <terminateThreads+0xb0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [9 x i8] c"%s: %d: \00"
@.str.1 = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/CRUx-BPHC/crux-judge/refs/heads/development/src/server/contest/sandbox/terminate.c\00"
@.str.2 = [33 x i8] c"pthread_cancel failed: errno: %d\00"
@errno = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
define void @terminateThreads(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %29, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %32
10: ; preds = %6
%11 = load i32*, i32** %3
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
%15 = load i32, i32* %14
%16 = call i32 @pthread_cancel(i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %28
18: ; preds = %10
br label %19
19: ; preds = %18
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.1, i64 0, i64 0), i32 153)
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %19
br label %28
28: ; preds = %27, %10
br label %29
29: ; preds = %28
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %6
32: ; preds = %6
store i32 0, i32* %5
br label %33
33: ; preds = %44, %32
%34 = load i32, i32* %5
%35 = load i32, i32* %4
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %47
37: ; preds = %33
%38 = load i32*, i32** %3
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32, i32* %41
%43 = call i32 @pthread_join(i32 %42, i32* null)
br label %44
44: ; preds = %37
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
br label %33
47: ; preds = %33
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [9 x i8] c"%s: %d: \00"
@.str.1 = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/CRUx-BPHC/crux-judge/refs/heads/development/src/server/contest/sandbox/terminate.c\00"
@.str.2 = [33 x i8] c"pthread_cancel failed: errno: %d\00"
@errno = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
define void @terminateThreads(i32* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %33
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %9
6: ; preds = %23
br i1 %3, label %7, label %33
7: ; preds = %6
%8 = zext i32 %1 to i64
br label %26
9: ; preds = %4, %23
%10 = phi i64 [ 0, %4 ], [ %24, %23 ]
%11 = getelementptr inbounds i32, i32* %0, i64 %10
%12 = load i32, i32* %11
%13 = tail call i32 @pthread_cancel(i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %23
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str.1, i64 0, i64 0), i32 153)
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %9, %15
%24 = add nuw nsw i64 %10, 1
%25 = icmp eq i64 %24, %5
br i1 %25, label %6, label %9
26: ; preds = %7, %26
%27 = phi i64 [ 0, %7 ], [ %31, %26 ]
%28 = getelementptr inbounds i32, i32* %0, i64 %27
%29 = load i32, i32* %28
%30 = tail call i32 @pthread_join(i32 %29, i32* null)
%31 = add nuw nsw i64 %27, 1
%32 = icmp eq i64 %31, %8
br i1 %32, label %33, label %26
33: ; preds = %26, %2, %6
ret void
}