#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int BUFSIZ;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ getData(int, char **);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void *task(const char ip[], int port, void *(*fnCallBack)(void *)) {
  int sockfd, newsockfd, portno = 7578, clilen;
  struct sockaddr_in serv_addr, cli_addr;
  char data[BUFSIZ];
  int i;
  void *returnVal;
  bzero((char *)&data, sizeof(char) * BUFSIZ);
  printf("using port #%d\n", portno);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0)
    error("ERROR opening socket");
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = INADDR_ANY;
  serv_addr.sin_port = htons(portno);
  if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
    error("ERROR on binding");
  listen(sockfd, 5);
  clilen = sizeof(cli_addr);
  while (1) {
    printf("waiting for new client...\n");
    if ((newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr,
                            (socklen_t *)&clilen)) < 0)
      error("ERROR on accept");
    printf("opened new communication with client\n");
    getData(newsockfd, &data);
    returnVal = fnCallBack(data);
    close(newsockfd);
  }
  close(sockfd);
  return returnVal;
}


x86 assembly (clang, -O0):
<task>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1d9a,-0x24(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x70(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x58(%rbp)
mov    0x2ddb(%rip),%rax
movslq (%rax),%rax
shl    $0x0,%rax
mov    %eax,%esi
call   10a0 <bzero@plt>
mov    -0x24(%rbp),%esi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    123e <task+0x9e>
lea    0xdd7(%rip),%rdi
call   1090 <error@plt>
lea    -0x38(%rbp),%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    1296 <task+0xf6>
lea    0xd94(%rip),%rdi
call   1090 <error@plt>
mov    -0x1c(%rbp),%edi
mov    $0x5,%esi
call   1070 <listen@plt>
movl   $0xc,-0x28(%rbp)
jmp    12af <task+0x10f>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    12e5 <task+0x145>
lea    0xd71(%rip),%rdi
call   1090 <error@plt>
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x70(%rbp),%rsi
mov    -0x20(%rbp),%edi
call   1030 <getData@plt>
mov    -0x70(%rbp),%rdi
call   *-0x18(%rbp)
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%edi
call   1060 <close@plt>
jmp    12aa <task+0x10a>

x86 assembly (clang, -O2):
<task>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,-0x40(%rbp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   10b0 <bzero@plt>
lea    0xe0f(%rip),%rdi
mov    $0x1d9a,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2de4(%rip),%r12
mov    (%r12),%edi
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    122b <task+0x7b>
lea    0xdea(%rip),%rdi
call   10a0 <error@plt>
lea    -0x38(%rbp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    (%r12),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    $0x1d9a,%edi
call   1050 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
test   %rax,%rax
jns    127d <task+0xcd>
lea    0xdad(%rip),%rdi
call   10a0 <error@plt>
mov    %r15d,%edi
mov    $0x5,%esi
call   1080 <listen@plt>
movl   $0xc,-0x2c(%rbp)
lea    -0x2c(%rbp),%r14
lea    0xdc4(%rip),%r12
jmp    12c1 <task+0x111>
xchg   %ax,%ax
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
call   1030 <getData@plt>
mov    %rbx,%rdi
call   *-0x40(%rbp)
mov    %r13d,%edi
call   1070 <close@plt>
lea    0xd7e(%rip),%rdi
call   1040 <puts@plt>
mov    %r15d,%edi
lea    -0x50(%rbp),%rsi
mov    %r14,%rdx
call   10c0 <accept@plt>
mov    %eax,%r13d
test   %eax,%eax
jns    12a0 <task+0xf0>
lea    0xd4c(%rip),%rdi
call   10a0 <error@plt>
jmp    12a0 <task+0xf0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@.str = [16 x i8] c"using port #%d\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [17 x i8] c"ERROR on binding\00"
@.str.3 = [27 x i8] c"waiting for new client...\0A\00"
@.str.4 = [16 x i8] c"ERROR on accept\00"
@.str.5 = [38 x i8] c"opened new communication with client\0A\00"
define i8* @task(i8* %0, i32 %1, i8* (i8*)* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8* (i8*)*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
%16 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* (i8*)* %2, i8* (i8*)** %6
store i32 7578, i32* %9
%17 = load i32, i32* @BUFSIZ
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %13
%20 = alloca i8, i64 %18
store i64 %18, i64* %14
%21 = load i32, i32* @BUFSIZ
%22 = sext i32 %21 to i64
%23 = mul i64 1, %22
%24 = trunc i64 %23 to i32
%25 = call i32 @bzero(i8* %20, i32 %24)
%26 = load i32, i32* %9
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load i32, i32* @AF_INET
%29 = load i32, i32* @SOCK_STREAM
%30 = call i32 @socket(i32 %28, i32 %29, i32 0)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %3
%34 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %3
%36 = bitcast %struct.sockaddr_in* %11 to i8*
%37 = call i32 @bzero(i8* %36, i32 12)
%38 = load i32, i32* @AF_INET
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %38, i32* %39
%40 = load i32, i32* @INADDR_ANY
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%42 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %41, i32 0, i32 0
store i32 %40, i32* %42
%43 = load i32, i32* %9
%44 = call i32 @htons(i32 %43)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %44, i32* %45
%46 = load i32, i32* %7
%47 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%48 = call i64 @bind(i32 %46, %struct.sockaddr* %47, i32 12)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %35
%51 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %50, %35
%53 = load i32, i32* %7
%54 = call i32 @listen(i32 %53, i32 5)
store i32 12, i32* %10
br label %55
55: ; preds = %64, %52
br label %56
56: ; preds = %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%58 = load i32, i32* %7
%59 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%60 = call i32 @accept(i32 %58, %struct.sockaddr* %59, i32* %10)
store i32 %60, i32* %8
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %56
%63 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %64
64: ; preds = %62, %56
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
%66 = load i32, i32* %8
%67 = bitcast i8* %20 to i8**
%68 = call i32 @getData(i32 %66, i8** %67)
%69 = load i8* (i8*)*, i8* (i8*)** %6
%70 = call i8* %69(i8* %20)
store i8* %70, i8** %16
%71 = load i32, i32* %8
%72 = call i32 @close(i32 %71)
br label %55
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@.str = [16 x i8] c"using port #%d\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [17 x i8] c"ERROR on binding\00"
@.str.4 = [16 x i8] c"ERROR on accept\00"
@str = [26 x i8] c"waiting for new client...\00"
@str.6 = [37 x i8] c"opened new communication with client\00"
define i8* @task(i8* nocapture readnone %0, i32 %1, i8* (i8*)* nocapture %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = bitcast i32* %4 to i8*
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = bitcast %struct.sockaddr_in* %6 to i8*
%10 = load i32, i32* @BUFSIZ
%11 = zext i32 %10 to i64
%12 = alloca i8, i64 %11
%13 = call i32 @bzero(i8* %12, i32 %10)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 7578)
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %3
%20 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %3
%22 = call i32 @bzero(i8* %8, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %25, i32* %26
%27 = tail call i32 @htons(i32 7578)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %27, i32* %28
%29 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%30 = call i64 @bind(i32 %17, %struct.sockaddr* %29, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %21
%35 = call i32 @listen(i32 %17, i32 5)
store i32 12, i32* %4
%36 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%37 = bitcast i8* %12 to i8**
br label %38
38: ; preds = %44, %34
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%40 = call i32 @accept(i32 %17, %struct.sockaddr* %36, i32* %4)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.6, i64 0, i64 0))
%46 = call i32 @getData(i32 %40, i8** %37)
%47 = call i8* %2(i8* %12)
%48 = call i32 @close(i32 %40)
br label %38
}