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

/* Variables and functions */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
unsigned char *pointerFollower(unsigned char *, unsigned char, int);
unsigned char *unpointerfy(unsigned char *response, int initLocation,
                           int size) {
  int currentLocation = initLocation;
  unsigned char *fixedResponse =
      (unsigned char *)calloc(size * 5, sizeof(char));
  int bytesAdded = 0;
  memset(fixedResponse, 0, size * 5);
  while (currentLocation < size) {
    if (*(response + currentLocation) == 0xc0) {
      unsigned char *tmpnamebuf =
          (unsigned char *)calloc(100, sizeof(unsigned char));
      memset(tmpnamebuf, 0, 100);
      tmpnamebuf = pointerFollower(response, *(response + currentLocation + 1),
                                   currentLocation);
      currentLocation += 2;
      int i = 0;
      while (tmpnamebuf[i] != '\0') {
        i++;
      }
      memcpy(fixedResponse + bytesAdded, tmpnamebuf, i);
      bytesAdded += i + 1;
    } else {
      memcpy(fixedResponse + bytesAdded, response + currentLocation, 1);
      currentLocation++;
      bytesAdded++;
    }
  }
  return fixedResponse;
}


x86 assembly (clang, -O0):
<unpointerfy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
imul   $0x5,-0x10(%rbp),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
imul   $0x5,-0x10(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1277 <unpointerfy+0x137>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0xc0,%eax
jne    1240 <unpointerfy+0x100>
mov    $0x64,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    0x1(%rax,%rcx,1),%al
mov    -0x14(%rbp),%edx
movzbl %al,%esi
call   1060 <pointerFollower@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1218 <unpointerfy+0xd8>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11f5 <unpointerfy+0xb5>
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1272 <unpointerfy+0x132>
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1180 <unpointerfy+0x40>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpointerfy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r13d
mov    %rdi,%r12
lea    (%rbx,%rbx,4),%r14d
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
xor    %ebp,%ebp
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1030 <memset@plt>
mov    %rbx,(%rsp)
cmp    %ebx,%r13d
jl     11c6 <unpointerfy+0x86>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movslq %ebp,%rdi
add    %r15,%rdi
mov    $0x1,%r14d
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
add    $0x1,%r13d
add    %r14d,%ebp
cmp    (%rsp),%r13d
jge    117f <unpointerfy+0x3f>
movslq %r13d,%rax
lea    (%r12,%rax,1),%rbx
cmpb   $0xc0,(%r12,%rax,1)
jne    11a0 <unpointerfy+0x60>
mov    $0x64,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1030 <memset@plt>
movzbl 0x1(%rbx),%esi
mov    %r12,%rdi
mov    %r13d,%edx
call   1060 <pointerFollower@plt>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x0,(%rax,%r14,1)
lea    0x1(%r14),%r14
jne    1210 <unpointerfy+0xd0>
add    $0x2,%r13d
lea    -0x1(%r14),%edx
movslq %ebp,%rdi
add    %r15,%rdi
mov    %rax,%rsi
call   1050 <memcpy@plt>
jmp    11bd <unpointerfy+0x7d>

LLVM IR (-O0):
define i8* @unpointerfy(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i32, i32* %5
store i32 %12, i32* %7
%13 = load i32, i32* %6
%14 = mul nsw i32 %13, 5
%15 = call i64 @calloc(i32 %14, i32 1)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %8
store i32 0, i32* %9
%17 = load i8*, i8** %8
%18 = load i32, i32* %6
%19 = mul nsw i32 %18, 5
%20 = call i32 @memset(i8* %17, i32 0, i32 %19)
br label %21
21: ; preds = %86, %3
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %87
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = icmp eq i32 %31, 192
br i1 %32, label %33, label %72
33: ; preds = %25
%34 = call i64 @calloc(i32 100, i32 1)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %10
%36 = load i8*, i8** %10
%37 = call i32 @memset(i8* %36, i32 0, i32 100)
%38 = load i8*, i8** %4
%39 = load i8*, i8** %4
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %43
%45 = load i32, i32* %7
%46 = call i8* @pointerFollower(i8* %38, i8 zeroext %44, i32 %45)
store i8* %46, i8** %10
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 2
store i32 %48, i32* %7
store i32 0, i32* %11
br label %49
49: ; preds = %57, %33
%50 = load i8*, i8** %10
%51 = load i32, i32* %11
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %49
%58 = load i32, i32* %11
%59 = add nsw i32 %58, 1
store i32 %59, i32* %11
br label %49
60: ; preds = %49
%61 = load i8*, i8** %8
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i8*, i8** %10
%66 = load i32, i32* %11
%67 = call i32 @memcpy(i8* %64, i8* %65, i32 %66)
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 1
%70 = load i32, i32* %9
%71 = add nsw i32 %70, %69
store i32 %71, i32* %9
br label %86
72: ; preds = %25
%73 = load i8*, i8** %8
%74 = load i32, i32* %9
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = load i8*, i8** %4
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
%81 = call i32 @memcpy(i8* %76, i8* %80, i32 1)
%82 = load i32, i32* %7
%83 = add nsw i32 %82, 1
store i32 %83, i32* %7
%84 = load i32, i32* %9
%85 = add nsw i32 %84, 1
store i32 %85, i32* %9
br label %86
86: ; preds = %72, %60
br label %21
87: ; preds = %21
%88 = load i8*, i8** %8
ret i8* %88
}

LLVM IR (-O2):
define i8* @unpointerfy(i8* %0, i32 %1, i32 %2) {
%4 = mul nsw i32 %2, 5
%5 = tail call i64 @calloc(i32 %4, i32 1)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @memset(i8* %6, i32 0, i32 %4)
%8 = icmp slt i32 %1, %2
br i1 %8, label %9, label %46
9: ; preds = %3, %41
%10 = phi i32 [ %44, %41 ], [ 0, %3 ]
%11 = phi i32 [ %42, %41 ], [ %1, %3 ]
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, -64
br i1 %15, label %16, label %36
16: ; preds = %9
%17 = tail call i64 @calloc(i32 100, i32 1)
%18 = inttoptr i64 %17 to i8*
%19 = tail call i32 @memset(i8* %18, i32 0, i32 100)
%20 = getelementptr inbounds i8, i8* %13, i64 1
%21 = load i8, i8* %20
%22 = tail call i8* @pointerFollower(i8* %0, i8 zeroext %21, i32 %11)
br label %23
23: ; preds = %23, %16
%24 = phi i64 [ %28, %23 ], [ 0, %16 ]
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
%28 = add nuw i64 %24, 1
br i1 %27, label %29, label %23
29: ; preds = %23
%30 = add nsw i32 %11, 2
%31 = trunc i64 %24 to i32
%32 = sext i32 %10 to i64
%33 = getelementptr inbounds i8, i8* %6, i64 %32
%34 = tail call i32 @memcpy(i8* %33, i8* %22, i32 %31)
%35 = add nuw nsw i32 %31, 1
br label %41
36: ; preds = %9
%37 = sext i32 %10 to i64
%38 = getelementptr inbounds i8, i8* %6, i64 %37
%39 = tail call i32 @memcpy(i8* %38, i8* %13, i32 1)
%40 = add nsw i32 %11, 1
br label %41
41: ; preds = %36, %29
%42 = phi i32 [ %30, %29 ], [ %40, %36 ]
%43 = phi i32 [ %35, %29 ], [ 1, %36 ]
%44 = add nsw i32 %43, %10
%45 = icmp slt i32 %42, %2
br i1 %45, label %9, label %46
46: ; preds = %41, %3
ret i8* %6
}