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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ recvall(int, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(char *, char *, int);
int strnlen(char *, int);
int boithoa_getLdapResponsList(int socketha, char **respons_list[],
                               int *nrofresponses) {
  char ldaprecord[512];
  int intresponse, i, len;
  if (!recvall(socketha, &intresponse, sizeof(intresponse))) {
    return 0;
  }
  if (((*respons_list) = malloc((sizeof(char *) * (intresponse + 1)))) ==
      NULL) {
    perror("boithoa_getLdapResponsList: can't malloc respons array");
    return 0;
  }
  *nrofresponses = 0;
  for (i = 0; i < intresponse; i++) {
    if (!recvall(socketha, ldaprecord, sizeof(ldaprecord))) {
      fprintf(stderr, "can't recvall() ldaprecord\n");
      return 0;
    }
    len = strnlen(ldaprecord, 512);
    (*respons_list)[*nrofresponses] = malloc(len + 1);
    strncpy((*respons_list)[*nrofresponses], ldaprecord, len + 1);
    (*nrofresponses)++;
  }
  (*respons_list)[*nrofresponses] = NULL;
  return 1;
}


x86 assembly (clang, -O0):
<boithoa_getLdapResponsList>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x224(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <recvall@plt>
cmp    $0x0,%eax
jne    11a1 <boithoa_getLdapResponsList+0x41>
movl   $0x0,-0x4(%rbp)
jmp    12e3 <boithoa_getLdapResponsList+0x183>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11e0 <boithoa_getLdapResponsList+0x80>
lea    0xe31(%rip),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e3 <boithoa_getLdapResponsList+0x183>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x228(%rbp)
mov    -0x228(%rbp),%eax
cmp    -0x224(%rbp),%eax
jge    12c6 <boithoa_getLdapResponsList+0x166>
mov    -0x8(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
mov    $0x0,%al
call   1050 <recvall@plt>
cmp    $0x0,%eax
jne    1246 <boithoa_getLdapResponsList+0xe6>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e3 <boithoa_getLdapResponsList+0x183>
lea    -0x220(%rbp),%rdi
mov    $0x200,%esi
call   1040 <strnlen@plt>
mov    %eax,-0x22c(%rbp)
mov    -0x22c(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x220(%rbp),%rsi
mov    -0x22c(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x228(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x228(%rbp)
jmp    11f4 <boithoa_getLdapResponsList+0x94>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<boithoa_getLdapResponsList>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rdx,%r13
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebp,%ebp
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1050 <recvall@plt>
test   %eax,%eax
je     125b <boithoa_getLdapResponsList+0xfb>
mov    0xc(%rsp),%ebx
lea    0x8(,%rbx,8),%edi
call   1070 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     126f <boithoa_getLdapResponsList+0x10f>
movl   $0x0,0x0(%r13)
test   %ebx,%ebx
jle    1233 <boithoa_getLdapResponsList+0xd3>
lea    0x10(%rsp),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x200,%edx
mov    %r15d,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <recvall@plt>
test   %eax,%eax
je     1244 <boithoa_getLdapResponsList+0xe4>
mov    %r12,%rdi
mov    $0x200,%esi
call   1040 <strnlen@plt>
lea    0x1(%rax),%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    (%r14),%rcx
movslq 0x0(%r13),%rdx
mov    %rax,(%rcx,%rdx,8)
mov    (%r14),%rax
mov    (%rax,%rdx,8),%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq 0x0(%r13),%rcx
add    $0x1,%rcx
mov    %ecx,0x0(%r13)
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
jl     11d0 <boithoa_getLdapResponsList+0x70>
mov    (%r14),%rax
jmp    1235 <boithoa_getLdapResponsList+0xd5>
xor    %ecx,%ecx
movq   $0x0,(%rax,%rcx,8)
mov    $0x1,%ebp
jmp    125b <boithoa_getLdapResponsList+0xfb>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
call   1060 <fprintf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd8a(%rip),%rdi
call   1080 <perror@plt>
jmp    125b <boithoa_getLdapResponsList+0xfb>

LLVM IR (-O0):
@.str = [55 x i8] c"boithoa_getLdapResponsList: can't malloc respons array\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"can't recvall() ldaprecord\0A\00"
define i32 @boithoa_getLdapResponsList(i32 %0, i8*** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8***
%7 = alloca i32*
%8 = alloca [512 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i8*** %1, i8**** %6
store i32* %2, i32** %7
%12 = load i32, i32* %5
%13 = call i32 (i32, ...) @recvall(i32 %12, i32* %9, i64 4)
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %3
store i32 0, i32* %4
br label %78
16: ; preds = %3
%17 = load i32, i32* %9
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = mul i64 8, %19
%21 = trunc i64 %20 to i32
%22 = call i8* @malloc(i32 %21)
%23 = bitcast i8* %22 to i8**
%24 = load i8***, i8**** %6
store i8** %23, i8*** %24
%25 = icmp eq i8** %23, null
br i1 %25, label %26, label %28
26: ; preds = %16
%27 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %78
28: ; preds = %16
%29 = load i32*, i32** %7
store i32 0, i32* %29
store i32 0, i32* %10
br label %30
30: ; preds = %68, %28
%31 = load i32, i32* %10
%32 = load i32, i32* %9
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %71
34: ; preds = %30
%35 = load i32, i32* %5
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%37 = call i32 (i32, ...) @recvall(i32 %35, i8* %36, i64 512)
%38 = icmp ne i32 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %78
42: ; preds = %34
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%44 = call i32 @strnlen(i8* %43, i32 512)
store i32 %44, i32* %11
%45 = load i32, i32* %11
%46 = add nsw i32 %45, 1
%47 = call i8* @malloc(i32 %46)
%48 = load i8***, i8**** %6
%49 = load i8**, i8*** %48
%50 = load i32*, i32** %7
%51 = load i32, i32* %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %49, i64 %52
store i8* %47, i8** %53
%54 = load i8***, i8**** %6
%55 = load i8**, i8*** %54
%56 = load i32*, i32** %7
%57 = load i32, i32* %56
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %55, i64 %58
%60 = load i8*, i8** %59
%61 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%62 = load i32, i32* %11
%63 = add nsw i32 %62, 1
%64 = call i32 @strncpy(i8* %60, i8* %61, i32 %63)
%65 = load i32*, i32** %7
%66 = load i32, i32* %65
%67 = add nsw i32 %66, 1
store i32 %67, i32* %65
br label %68
68: ; preds = %42
%69 = load i32, i32* %10
%70 = add nsw i32 %69, 1
store i32 %70, i32* %10
br label %30
71: ; preds = %30
%72 = load i8***, i8**** %6
%73 = load i8**, i8*** %72
%74 = load i32*, i32** %7
%75 = load i32, i32* %74
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8*, i8** %73, i64 %76
store i8* null, i8** %77
store i32 1, i32* %4
br label %78
78: ; preds = %71, %39, %26, %15
%79 = load i32, i32* %4
ret i32 %79
}

LLVM IR (-O2):
@.str = [55 x i8] c"boithoa_getLdapResponsList: can't malloc respons array\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"can't recvall() ldaprecord\0A\00"
define i32 @boithoa_getLdapResponsList(i32 %0, i8*** nocapture %1, i32* nocapture %2) {
%4 = alloca [512 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = bitcast i32* %5 to i8*
%8 = call i32 (i32, ...) @recvall(i32 %0, i32* %5, i64 4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %53, label %10
10: ; preds = %3
%11 = load i32, i32* %5
%12 = shl i32 %11, 3
%13 = add i32 %12, 8
%14 = call i8* @malloc(i32 %13)
%15 = bitcast i8*** %1 to i8**
store i8* %14, i8** %15
%16 = icmp eq i8* %14, null
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
br label %53
19: ; preds = %10
%20 = bitcast i8* %14 to i8**
store i32 0, i32* %2
%21 = icmp sgt i32 %11, 0
br i1 %21, label %22, label %49
22: ; preds = %19, %29
%23 = phi i32 [ %43, %29 ], [ 0, %19 ]
%24 = call i32 (i32, ...) @recvall(i32 %0, i8* %6, i64 512)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %53
29: ; preds = %22
%30 = call i32 @strnlen(i8* %6, i32 512)
%31 = add nsw i32 %30, 1
%32 = call i8* @malloc(i32 %31)
%33 = load i8**, i8*** %1
%34 = load i32, i32* %2
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
store i8* %32, i8** %36
%37 = load i8**, i8*** %1
%38 = getelementptr inbounds i8*, i8** %37, i64 %35
%39 = load i8*, i8** %38
%40 = call i32 @strncpy(i8* %39, i8* %6, i32 %31)
%41 = load i32, i32* %2
%42 = add nsw i32 %41, 1
store i32 %42, i32* %2
%43 = add nuw nsw i32 %23, 1
%44 = load i32, i32* %5
%45 = icmp slt i32 %43, %44
br i1 %45, label %22, label %46
46: ; preds = %29
%47 = load i8**, i8*** %1
%48 = sext i32 %42 to i64
br label %49
49: ; preds = %46, %19
%50 = phi i64 [ %48, %46 ], [ 0, %19 ]
%51 = phi i8** [ %47, %46 ], [ %20, %19 ]
%52 = getelementptr inbounds i8*, i8** %51, i64 %50
store i8* null, i8** %52
br label %53
53: ; preds = %3, %49, %26, %17
%54 = phi i32 [ 0, %17 ], [ 0, %26 ], [ 1, %49 ], [ 0, %3 ]
ret i32 %54
}