#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;
typedef int /*<<< orphan*/ pthread_attr_t;

/* Variables and functions */
int init_pthread_attr(int /*<<< orphan*/ *, int const);
int /*<<< orphan*/ logError(char *, int, int, int, char *);
int /*<<< orphan*/ pthread_attr_destroy(int /*<<< orphan*/ *);
int pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   void *(*)(void *), void *);
char *strerror(int);
int create_work_threads(int *count, void *(*start_func)(void *), void *arg,
                        pthread_t *tids, const int stack_size) {
  int result;
  pthread_attr_t thread_attr;
  pthread_t *ptid;
  pthread_t *ptid_end;
  if ((result = init_pthread_attr(&thread_attr, stack_size)) != 0) {
    return result;
  }
  result = 0;
  ptid_end = tids + (*count);
  for (ptid = tids; ptid < ptid_end; ptid++) {
    if ((result = pthread_create(ptid, &thread_attr, start_func, arg)) != 0) {
      *count = ptid - tids;
      logError("file: "
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/"
               "master/fastdfs-5.01/common/pthread_func.c"
               ", line: %d, "
               "create thread failed, startup threads: %d, "
               "errno: %d, error info: %s",
               169, *count, result,
               (strerror(result) != NULL ? strerror(result) : "Unkown error"));
      break;
    }
  }
  pthread_attr_destroy(&thread_attr);
  return result;
}


x86 assembly (clang, -O0):
<create_work_threads>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    -0x34(%rbp),%rdi
call   1040 <init_pthread_attr@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
je     118f <create_work_threads+0x3f>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1281 <create_work_threads+0x131>
movl   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x48(%rbp),%rax
jae    1272 <create_work_threads+0x122>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x34(%rbp),%rsi
call   1050 <pthread_create@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
je     125c <create_work_threads+0x10c>
mov    -0x40(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x30(%rbp),%edi
call   1070 <strerror@plt>
cmp    $0x0,%rax
je     122c <create_work_threads+0xdc>
mov    -0x30(%rbp),%edi
call   1070 <strerror@plt>
mov    %rax,-0x58(%rbp)
jmp    123c <create_work_threads+0xec>
lea    0xec3(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    123c <create_work_threads+0xec>
mov    -0x4c(%rbp),%ecx
mov    -0x50(%rbp),%edx
mov    -0x58(%rbp),%r8
lea    0xdb3(%rip),%rdi
mov    $0xa9,%esi
call   1030 <logError@plt>
jmp    1272 <create_work_threads+0x122>
jmp    1261 <create_work_threads+0x111>
mov    -0x40(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x40(%rbp)
jmp    11b4 <create_work_threads+0x64>
lea    -0x34(%rbp),%rdi
call   1060 <pthread_attr_destroy@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_work_threads>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbp
lea    0xc(%rsp),%rdi
mov    %r8d,%esi
call   1040 <init_pthread_attr@plt>
mov    %eax,%r14d
test   %eax,%eax
jne    1213 <create_work_threads+0xc3>
movslq 0x0(%rbp),%rax
test   %rax,%rax
jle    11c3 <create_work_threads+0x73>
mov    %rbp,0x10(%rsp)
lea    (%rbx,%rax,4),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
mov    %r13,%rdx
mov    %r12,%rcx
call   1050 <pthread_create@plt>
test   %eax,%eax
jne    11c8 <create_work_threads+0x78>
add    $0x4,%rbx
add    $0x1,%ebp
cmp    %r15,%rbx
jb     11a0 <create_work_threads+0x50>
xor    %r14d,%r14d
jmp    1209 <create_work_threads+0xb9>
mov    %eax,%r14d
mov    0x10(%rsp),%rax
mov    %ebp,(%rax)
mov    %r14d,%edi
call   1070 <strerror@plt>
test   %rax,%rax
je     11ec <create_work_threads+0x9c>
mov    %r14d,%edi
call   1070 <strerror@plt>
mov    %rax,%r8
jmp    11f3 <create_work_threads+0xa3>
lea    0xf03(%rip),%r8
lea    0xe06(%rip),%rdi
mov    $0xa9,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1030 <logError@plt>
lea    0xc(%rsp),%rdi
call   1060 <pthread_attr_destroy@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [246 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/pthread_func.c, line: %d, create thread failed, startup threads: %d, errno: %d, error info: %s\00"
@.str.1 = [13 x i8] c"Unkown error\00"
define i32 @create_work_threads(i32* %0, i8* (i8*)* %1, i8* %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8* (i8*)*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32*
store i32* %0, i32** %7
store i8* (i8*)* %1, i8* (i8*)** %8
store i8* %2, i8** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
%16 = load i32, i32* %11
%17 = call i32 @init_pthread_attr(i32* %13, i32 %16)
store i32 %17, i32* %12
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %5
%20 = load i32, i32* %12
store i32 %20, i32* %6
br label %67
21: ; preds = %5
store i32 0, i32* %12
%22 = load i32*, i32** %10
%23 = load i32*, i32** %7
%24 = load i32, i32* %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %22, i64 %25
store i32* %26, i32** %15
%27 = load i32*, i32** %10
store i32* %27, i32** %14
br label %28
28: ; preds = %61, %21
%29 = load i32*, i32** %14
%30 = load i32*, i32** %15
%31 = icmp ult i32* %29, %30
br i1 %31, label %32, label %64
32: ; preds = %28
%33 = load i32*, i32** %14
%34 = load i8* (i8*)*, i8* (i8*)** %8
%35 = load i8*, i8** %9
%36 = call i32 @pthread_create(i32* %33, i32* %13, i8* (i8*)* %34, i8* %35)
store i32 %36, i32* %12
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %60
38: ; preds = %32
%39 = load i32*, i32** %14
%40 = load i32*, i32** %10
%41 = ptrtoint i32* %39 to i64
%42 = ptrtoint i32* %40 to i64
%43 = sub i64 %41, %42
%44 = sdiv exact i64 %43, 4
%45 = trunc i64 %44 to i32
%46 = load i32*, i32** %7
store i32 %45, i32* %46
%47 = load i32*, i32** %7
%48 = load i32, i32* %47
%49 = load i32, i32* %12
%50 = load i32, i32* %12
%51 = call i8* @strerror(i32 %50)
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %56
53: ; preds = %38
%54 = load i32, i32* %12
%55 = call i8* @strerror(i32 %54)
br label %57
56: ; preds = %38
br label %57
57: ; preds = %56, %53
%58 = phi i8* [ %55, %53 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %56 ]
%59 = call i32 @logError(i8* getelementptr inbounds ([246 x i8], [246 x i8]* @.str, i64 0, i64 0), i32 169, i32 %48, i32 %49, i8* %58)
br label %64
60: ; preds = %32
br label %61
61: ; preds = %60
%62 = load i32*, i32** %14
%63 = getelementptr inbounds i32, i32* %62, i32 1
store i32* %63, i32** %14
br label %28
64: ; preds = %57, %28
%65 = call i32 @pthread_attr_destroy(i32* %13)
%66 = load i32, i32* %12
store i32 %66, i32* %6
br label %67
67: ; preds = %64, %19
%68 = load i32, i32* %6
ret i32 %68
}

LLVM IR (-O2):
@.str = [246 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/pthread_func.c, line: %d, create thread failed, startup threads: %d, errno: %d, error info: %s\00"
@.str.1 = [13 x i8] c"Unkown error\00"
define i32 @create_work_threads(i32* nocapture %0, i8* (i8*)* %1, i8* %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = call i32 @init_pthread_attr(i32* %6, i32 %4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %38
10: ; preds = %5
%11 = load i32, i32* %0
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %3, i64 %12
%14 = icmp sgt i32 %11, 0
br i1 %14, label %15, label %35
15: ; preds = %10, %32
%16 = phi i32* [ %33, %32 ], [ %3, %10 ]
%17 = call i32 @pthread_create(i32* %16, i32* %6, i8* (i8*)* %1, i8* %2)
%18 = icmp eq i32 %17, 0
br i1 %18, label %32, label %19
19: ; preds = %15
%20 = ptrtoint i32* %16 to i64
%21 = ptrtoint i32* %3 to i64
%22 = sub i64 %20, %21
%23 = lshr exact i64 %22, 2
%24 = trunc i64 %23 to i32
store i32 %24, i32* %0
%25 = call i8* @strerror(i32 %17)
%26 = icmp eq i8* %25, null
br i1 %26, label %29, label %27
27: ; preds = %19
%28 = call i8* @strerror(i32 %17)
br label %29
29: ; preds = %19, %27
%30 = phi i8* [ %28, %27 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %19 ]
%31 = call i32 @logError(i8* getelementptr inbounds ([246 x i8], [246 x i8]* @.str, i64 0, i64 0), i32 169, i32 %24, i32 %17, i8* %30)
br label %35
32: ; preds = %15
%33 = getelementptr inbounds i32, i32* %16, i64 1
%34 = icmp ult i32* %33, %13
br i1 %34, label %15, label %35
35: ; preds = %32, %10, %29
%36 = phi i32 [ %17, %29 ], [ 0, %10 ], [ 0, %32 ]
%37 = call i32 @pthread_attr_destroy(i32* %6)
br label %38
38: ; preds = %5, %35
%39 = phi i32 [ %36, %35 ], [ %8, %5 ]
ret i32 %39
}