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

/* Variables and functions */
int /*<<< orphan*/ EVP_DigestFinal_ex(int /*<<< orphan*/ *, unsigned char *,
                                      unsigned int *);
int /*<<< orphan*/ EVP_DigestInit_ex(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_DigestUpdate(int /*<<< orphan*/ *, char *, int);
int EVP_MAX_MD_SIZE;
int /*<<< orphan*/ *EVP_MD_CTX_create();
int /*<<< orphan*/ EVP_MD_CTX_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_MD_CTX_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_cleanup();
int /*<<< orphan*/ EVP_sha256();
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
void *processRequest(void *args) {
  int *newsockfd = (int *)args;
  int n;
  char buf[256];
  unsigned char md_value[EVP_MAX_MD_SIZE];
  char sha256res[2 * EVP_MAX_MD_SIZE + 2];
  char *ptr;
  unsigned int md_len;
  ptr = sha256res;
  EVP_MD_CTX *ctx;
  printf("Enter pthread\n");
  ctx = EVP_MD_CTX_create();
  EVP_MD_CTX_init(ctx);
  EVP_DigestInit_ex(ctx, EVP_sha256(), NULL);
  while ((n = read(*newsockfd, buf, 256)) > 0) {
    EVP_DigestUpdate(ctx, buf, n);
  }
  EVP_DigestFinal_ex(ctx, md_value, &md_len);
  EVP_MD_CTX_destroy(ctx);
  for (n = 0; n < md_len; n++) {
    ptr += sprintf(ptr, "%02x", md_value[n]);
  }
  sprintf(ptr, "\n");
  *(ptr + 1) = '\0';
  if (write(*newsockfd, sha256res, strlen(sha256res)) < 0) {
    error("ERROR writing to socket");
  }
  close(*newsockfd);
  free(newsockfd);
  EVP_cleanup();
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<processRequest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2dba(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x128(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x168(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x130(%rbp)
mov    (%rax),%ecx
mov    %ecx,%eax
lea    0x2(%rax,%rax,1),%eax
mov    %eax,%ecx
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x160(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x138(%rbp)
mov    %rax,-0x140(%rbp)
lea    0xd6a(%rip),%rdi
call   1070 <printf@plt>
mov    $0x0,%al
call   1130 <EVP_MD_CTX_create@plt>
mov    %rax,-0x150(%rbp)
mov    -0x150(%rbp),%rdi
call   10f0 <EVP_MD_CTX_init@plt>
mov    -0x150(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    $0x0,%al
call   1120 <EVP_sha256@plt>
mov    -0x158(%rbp),%rdi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   10a0 <EVP_DigestInit_ex@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1090 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    131a <processRequest+0x10a>
mov    -0x150(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10c0 <EVP_DigestUpdate@plt>
jmp    12dc <processRequest+0xcc>
mov    -0x168(%rbp),%rsi
mov    -0x150(%rbp),%rdi
lea    -0x144(%rbp),%rdx
call   1040 <EVP_DigestFinal_ex@plt>
mov    -0x150(%rbp),%rdi
call   10e0 <EVP_MD_CTX_destroy@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x144(%rbp),%eax
jae    139e <processRequest+0x18e>
mov    -0x168(%rbp),%rax
mov    -0x140(%rbp),%rdi
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xc9c(%rip),%rsi
mov    $0x0,%al
call   1110 <sprintf@plt>
mov    %eax,%ecx
mov    -0x140(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x140(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1347 <processRequest+0x137>
mov    -0x140(%rbp),%rdi
lea    0xc61(%rip),%rsi
mov    $0x0,%al
call   1110 <sprintf@plt>
mov    -0x160(%rbp),%rdi
mov    -0x140(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x16c(%rbp)
call   1060 <strlen@plt>
mov    -0x16c(%rbp),%edi
mov    -0x160(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    1400 <processRequest+0x1f0>
lea    0xc19(%rip),%rdi
call   1100 <error@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1080 <close@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   10b0 <EVP_cleanup@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <pthread_exit@plt>
mov    -0x128(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<processRequest>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%r14
mov    %rsp,-0x40(%rbp)
mov    0x2db6(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%r12
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r12
mov    %r12,%rsp
mov    (%rax),%eax
add    %eax,%eax
add    $0x2,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
lea    0xdb9(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1130 <EVP_MD_CTX_create@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   10f0 <EVP_MD_CTX_init@plt>
xor    %eax,%eax
call   1120 <EVP_sha256@plt>
mov    %r13,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   10a0 <EVP_DigestInit_ex@plt>
mov    (%r14),%edi
lea    -0x140(%rbp),%rsi
mov    $0x100,%edx
call   1090 <read@plt>
test   %eax,%eax
jle    12d1 <processRequest+0xc1>
lea    -0x140(%rbp),%rbx
nopl   (%rax)
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10c0 <EVP_DigestUpdate@plt>
mov    (%r14),%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1090 <read@plt>
test   %eax,%eax
jg     12b0 <processRequest+0xa0>
lea    -0x2c(%rbp),%rdx
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <EVP_DigestFinal_ex@plt>
mov    %r13,%rdi
call   10e0 <EVP_MD_CTX_destroy@plt>
cmpl   $0x0,-0x2c(%rbp)
mov    %r15,-0x38(%rbp)
mov    %r15,%rbx
je     1333 <processRequest+0x123>
lea    0xd04(%rip),%r13
xor    %r15d,%r15d
mov    -0x38(%rbp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r12,%r15,1),%edx
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1110 <sprintf@plt>
cltq
add    %rax,%rbx
add    $0x1,%r15
mov    -0x2c(%rbp),%eax
cmp    %rax,%r15
jb     1310 <processRequest+0x100>
movw   $0xa,(%rbx)
mov    (%r14),%r15d
mov    -0x38(%rbp),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <write@plt>
test   %rax,%rax
jns    1365 <processRequest+0x155>
lea    0xca5(%rip),%rdi
call   1100 <error@plt>
mov    (%r14),%edi
call   1080 <close@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   10b0 <EVP_cleanup@plt>
xor    %edi,%edi
call   10d0 <pthread_exit@plt>
mov    -0x40(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EVP_MAX_MD_SIZE = global i32 0
@.str = [15 x i8] c"Enter pthread\0A\00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [24 x i8] c"ERROR writing to socket\00"
define i8* @processRequest(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32*
store i8* %0, i8** %3
%13 = load i8*, i8** %3
%14 = bitcast i8* %13 to i32*
store i32* %14, i32** %4
%15 = load i32, i32* @EVP_MAX_MD_SIZE
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %7
%18 = alloca i8, i64 %16
store i64 %16, i64* %8
%19 = load i32, i32* @EVP_MAX_MD_SIZE
%20 = mul nsw i32 2, %19
%21 = add nsw i32 %20, 2
%22 = zext i32 %21 to i64
%23 = alloca i8, i64 %22
store i64 %22, i64* %9
store i8* %23, i8** %10
%24 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%25 = call i32* (...) @EVP_MD_CTX_create()
store i32* %25, i32** %12
%26 = load i32*, i32** %12
%27 = call i32 @EVP_MD_CTX_init(i32* %26)
%28 = load i32*, i32** %12
%29 = call i32 (...) @EVP_sha256()
%30 = call i32 @EVP_DigestInit_ex(i32* %28, i32 %29, i32* null)
br label %31
31: ; preds = %37, %1
%32 = load i32*, i32** %4
%33 = load i32, i32* %32
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%35 = call i32 @read(i32 %33, i8* %34, i32 256)
store i32 %35, i32* %5
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i32*, i32** %12
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%40 = load i32, i32* %5
%41 = call i32 @EVP_DigestUpdate(i32* %38, i8* %39, i32 %40)
br label %31
42: ; preds = %31
%43 = load i32*, i32** %12
%44 = call i32 @EVP_DigestFinal_ex(i32* %43, i8* %18, i32* %11)
%45 = load i32*, i32** %12
%46 = call i32 @EVP_MD_CTX_destroy(i32* %45)
store i32 0, i32* %5
br label %47
47: ; preds = %62, %42
%48 = load i32, i32* %5
%49 = load i32, i32* %11
%50 = icmp ult i32 %48, %49
br i1 %50, label %51, label %65
51: ; preds = %47
%52 = load i8*, i8** %10
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %18, i64 %54
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = call i32 (i8*, i8*, ...) @sprintf(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %57)
%59 = load i8*, i8** %10
%60 = sext i32 %58 to i64
%61 = getelementptr inbounds i8, i8* %59, i64 %60
store i8* %61, i8** %10
br label %62
62: ; preds = %51
%63 = load i32, i32* %5
%64 = add nsw i32 %63, 1
store i32 %64, i32* %5
br label %47
65: ; preds = %47
%66 = load i8*, i8** %10
%67 = call i32 (i8*, i8*, ...) @sprintf(i8* %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%68 = load i8*, i8** %10
%69 = getelementptr inbounds i8, i8* %68, i64 1
store i8 0, i8* %69
%70 = load i32*, i32** %4
%71 = load i32, i32* %70
%72 = call i32 @strlen(i8* %23)
%73 = call i64 @write(i32 %71, i8* %23, i32 %72)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %65
%76 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %77
77: ; preds = %75, %65
%78 = load i32*, i32** %4
%79 = load i32, i32* %78
%80 = call i32 @close(i32 %79)
%81 = load i32*, i32** %4
%82 = call i32 @free(i32* %81)
%83 = call i32 (...) @EVP_cleanup()
%84 = call i32 @pthread_exit(i32* null)
%85 = load i8*, i8** %7
%86 = load i8*, i8** %2
ret i8* %86
}

LLVM IR (-O2):
@EVP_MAX_MD_SIZE = global i32 0
@.str.1 = [5 x i8] c"%02x\00"
@.str.3 = [24 x i8] c"ERROR writing to socket\00"
@str = [14 x i8] c"Enter pthread\00"
define noalias i8* @processRequest(i8* nocapture %0) {
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = bitcast i8* %0 to i32*
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @EVP_MAX_MD_SIZE
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = load i32, i32* @EVP_MAX_MD_SIZE
%11 = shl nsw i32 %10, 1
%12 = add nsw i32 %11, 2
%13 = zext i32 %12 to i64
%14 = alloca i8, i64 %13
%15 = bitcast i32* %3 to i8*
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%17 = tail call i32* (...) @EVP_MD_CTX_create()
%18 = tail call i32 @EVP_MD_CTX_init(i32* %17)
%19 = tail call i32 (...) @EVP_sha256()
%20 = tail call i32 @EVP_DigestInit_ex(i32* %17, i32 %19, i32* null)
%21 = load i32, i32* %4
%22 = call i32 @read(i32 %21, i8* %5, i32 256)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %1, %24
%25 = phi i32 [ %28, %24 ], [ %22, %1 ]
%26 = call i32 @EVP_DigestUpdate(i32* %17, i8* %5, i32 %25)
%27 = load i32, i32* %4
%28 = call i32 @read(i32 %27, i8* %5, i32 256)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %24, label %30
30: ; preds = %24, %1
%31 = call i32 @EVP_DigestFinal_ex(i32* %17, i8* %9, i32* %3)
%32 = call i32 @EVP_MD_CTX_destroy(i32* %17)
%33 = load i32, i32* %3
%34 = icmp eq i32 %33, 0
br i1 %34, label %48, label %35
35: ; preds = %30, %35
%36 = phi i64 [ %44, %35 ], [ 0, %30 ]
%37 = phi i8* [ %43, %35 ], [ %14, %30 ]
%38 = getelementptr inbounds i8, i8* %9, i64 %36
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %37, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %37, i64 %42
%44 = add nuw nsw i64 %36, 1
%45 = load i32, i32* %3
%46 = zext i32 %45 to i64
%47 = icmp ult i64 %44, %46
br i1 %47, label %35, label %48
48: ; preds = %35, %30
%49 = phi i8* [ %14, %30 ], [ %43, %35 ]
%50 = bitcast i8* %49 to i16*
store i16 10, i16* %50
%51 = load i32, i32* %4
%52 = call i32 @strlen(i8* %14)
%53 = call i64 @write(i32 %51, i8* %14, i32 %52)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %48
%56 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %57
57: ; preds = %55, %48
%58 = load i32, i32* %4
%59 = call i32 @close(i32 %58)
%60 = call i32 @free(i32* %4)
%61 = call i32 (...) @EVP_cleanup()
%62 = call i32 @pthread_exit(i32* null)
ret i8* undef
}