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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ errx(int, char *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int gdb_decode_hex(int, int);
int *malloc(size_t);
int /*<<< orphan*/ memset(int *, int, int);
int *realloc(int *, size_t);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
uint8_t *recv_packet(FILE *in, size_t *ret_size, bool *ret_sum_ok) {
  size_t i = 0;
  size_t size = 4096;
  uint8_t *reply = malloc(size);
  if (reply == NULL)
    err(1, "malloc");
  int c;
  uint8_t sum = 0;
  bool escape = false;
  while ((c = fgetc(in)) != EOF && c != '$')
    ;
  while ((c = fgetc(in)) != EOF) {
    sum += c;
    switch (c) {
    case '$':
      i = 0;
      sum = 0;
      escape = false;
      continue;
    case '#':
      sum -= c;
      {
        uint8_t msb = fgetc(in);
        uint8_t lsb = fgetc(in);
        *ret_sum_ok = sum == gdb_decode_hex(msb, lsb);
      }
      *ret_size = i;
      if (i == size) {
        reply = realloc(reply, size + 1);
        if (reply == NULL)
          err(1, "realloc");
      }
      reply[i] = '\0';
      return reply;
    case '}':
      escape = true;
      continue;
    case '*':
      if (i > 0) {
        int c2 = fgetc(in);
        if (c2 < 29 || c2 > 126 || c2 == '$' || c2 == '#') {
          ungetc(c2, in);
        } else {
          int count = c2 - 29;
          if (i + count > size) {
            size *= 2;
            reply = realloc(reply, size);
            if (reply == NULL)
              err(1, "realloc");
          }
          memset(&reply[i], reply[i - 1], count);
          i += count;
          sum += c2;
          continue;
        }
      }
    }
    if (escape) {
      c ^= 0x20;
      escape = false;
    }
    if (i == size) {
      size *= 2;
      reply = realloc(reply, size);
      if (reply == NULL)
        err(1, "realloc");
    }
    reply[i++] = c;
  }
  if (ferror(in))
    err(1, "recv");
  else if (feof(in))
    errx(0, "recv: Connection closed");
  else
    errx(1, "recv: Unknown connection error");
}


x86 assembly (clang, -O0):
<recv_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x1000,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11ed <recv_packet+0x4d>
mov    $0x1,%edi
lea    0xe18(%rip),%rsi
call   1090 <err@plt>
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x3c(%rbp)
xor    %eax,%eax
mov    0x2dd6(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x55(%rbp)
je     1227 <recv_packet+0x87>
cmpl   $0x24,-0x3c(%rbp)
setne  %al
mov    %al,-0x55(%rbp)
mov    -0x55(%rbp),%al
test   $0x1,%al
jne    1237 <recv_packet+0x97>
jmp    123c <recv_packet+0x9c>
jmp    11fb <recv_packet+0x5b>
jmp    1241 <recv_packet+0xa1>
mov    -0x10(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2d94(%rip),%rcx
cmp    (%rcx),%eax
je     1503 <recv_packet+0x363>
mov    -0x3c(%rbp),%ecx
mov    -0x40(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
sub    $0x23,%eax
je     12c9 <recv_packet+0x129>
jmp    127b <recv_packet+0xdb>
mov    -0x5c(%rbp),%eax
sub    $0x24,%eax
je     12ae <recv_packet+0x10e>
jmp    128c <recv_packet+0xec>
mov    -0x5c(%rbp),%eax
sub    $0x2a,%eax
je     1389 <recv_packet+0x1e9>
jmp    129d <recv_packet+0xfd>
mov    -0x5c(%rbp),%eax
sub    $0x7d,%eax
je     137d <recv_packet+0x1dd>
jmp    147f <recv_packet+0x2df>
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
jmp    1241 <recv_packet+0xa1>
mov    -0x3c(%rbp),%ecx
mov    -0x40(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x48(%rbp),%edi
mov    -0x4c(%rbp),%esi
call   1040 <gdb_decode_hex@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    1361 <recv_packet+0x1c1>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
add    $0x1,%rsi
call   10c0 <realloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    135c <recv_packet+0x1bc>
mov    $0x1,%edi
lea    0xcb0(%rip),%rsi
call   1090 <err@plt>
jmp    1361 <recv_packet+0x1c1>
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1568 <recv_packet+0x3c8>
movl   $0x1,-0x44(%rbp)
jmp    1241 <recv_packet+0xa1>
cmpq   $0x0,-0x28(%rbp)
jbe    147a <recv_packet+0x2da>
mov    -0x10(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x1d,-0x50(%rbp)
jl     13c8 <recv_packet+0x228>
cmpl   $0x7e,-0x50(%rbp)
jg     13c8 <recv_packet+0x228>
cmpl   $0x24,-0x50(%rbp)
je     13c8 <recv_packet+0x228>
cmpl   $0x23,-0x50(%rbp)
jne    13d9 <recv_packet+0x239>
mov    -0x50(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10b0 <ungetc@plt>
jmp    1475 <recv_packet+0x2d5>
mov    -0x50(%rbp),%eax
sub    $0x1d,%eax
mov    %eax,-0x54(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x54(%rbp),%rcx
add    %rcx,%rax
cmp    -0x30(%rbp),%rax
jbe    1435 <recv_packet+0x295>
mov    -0x30(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10c0 <realloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1430 <recv_packet+0x290>
mov    $0x1,%edi
lea    0xbdc(%rip),%rsi
call   1090 <err@plt>
jmp    1435 <recv_packet+0x295>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x54(%rbp),%edx
call   1060 <memset@plt>
movslq -0x54(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x50(%rbp),%eax
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    1241 <recv_packet+0xa1>
jmp    147a <recv_packet+0x2da>
jmp    147f <recv_packet+0x2df>
cmpl   $0x0,-0x44(%rbp)
je     1499 <recv_packet+0x2f9>
mov    -0x3c(%rbp),%eax
xor    $0x20,%eax
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    14e5 <recv_packet+0x345>
mov    -0x30(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10c0 <realloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    14e0 <recv_packet+0x340>
mov    $0x1,%edi
lea    0xb2c(%rip),%rsi
call   1090 <err@plt>
jmp    14e5 <recv_packet+0x345>
mov    -0x3c(%rbp),%edx
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x28(%rbp)
mov    %edx,(%rax,%rcx,4)
jmp    1241 <recv_packet+0xa1>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     152c <recv_packet+0x38c>
mov    $0x1,%edi
lea    0xaed(%rip),%rsi
call   1090 <err@plt>
jmp    1568 <recv_packet+0x3c8>
mov    -0x10(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     1552 <recv_packet+0x3b2>
xor    %edi,%edi
lea    0xacc(%rip),%rsi
call   1050 <errx@plt>
jmp    1563 <recv_packet+0x3c3>
mov    $0x1,%edi
lea    0xace(%rip),%rsi
call   1050 <errx@plt>
jmp    1568 <recv_packet+0x3c8>
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_packet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,0x28(%rsp)
mov    %rsi,0x30(%rsp)
mov    %rdi,%rbx
mov    $0x1000,%edi
call   10a0 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
jne    11e0 <recv_packet+0x40>
lea    0xe2a(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
mov    0x2e01(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <fgetc@plt>
cmp    $0x24,%eax
je     1202 <recv_packet+0x62>
cmp    0x0(%rbp),%eax
jne    11f0 <recv_packet+0x50>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
cmp    0x0(%rbp),%eax
jne    1236 <recv_packet+0x96>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     140f <recv_packet+0x26f>
lea    0xde8(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
jmp    14b8 <recv_packet+0x318>
mov    %eax,%r15d
xor    %r12d,%r12d
mov    $0x1000,%eax
mov    %rax,0x18(%rsp)
movl   $0x0,0x4(%rsp)
xor    %r14d,%r14d
mov    %rbx,0x10(%rsp)
mov    %r12,%r13
jmp    129f <recv_packet+0xff>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
mov    0x10(%rsp),%rbx
lea    (%rax,%r12,4),%rdi
mov    %rax,0x8(%rsp)
mov    -0x4(%rax,%r12,4),%esi
mov    %ebp,%edx
call   1060 <memset@plt>
add    0x20(%rsp),%r14d
mov    %rbx,%rdi
call   1070 <fgetc@plt>
mov    %eax,%r15d
mov    0x2d52(%rip),%rbp
cmp    0x0(%rbp),%eax
je     120f <recv_packet+0x6f>
mov    %r13,%r12
lea    (%r15,%r14,1),%eax
cmp    $0x2a,%r15d
mov    %rax,0x20(%rsp)
jne    1330 <recv_packet+0x190>
test   %r12,%r12
je     136c <recv_packet+0x1cc>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
mov    %eax,%r14d
lea    -0x23(%r14),%eax
cmp    $0x2,%eax
jb     1371 <recv_packet+0x1d1>
lea    -0x7f(%r14),%eax
cmp    $0xffffff9d,%eax
jbe    1371 <recv_packet+0x1d1>
lea    -0x1d(%r14),%ebp
lea    (%r12,%rbp,1),%r13
mov    0x18(%rsp),%rbx
cmp    %rbx,%r13
jbe    1260 <recv_packet+0xc0>
add    %rbx,%rbx
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   10c0 <realloc@plt>
test   %rax,%rax
mov    %rbx,0x18(%rsp)
jne    1265 <recv_packet+0xc5>
mov    $0x1,%edi
lea    0xce8(%rip),%rsi
call   1090 <err@plt>
xor    %eax,%eax
jmp    1265 <recv_packet+0xc5>
nopl   0x0(%rax,%rax,1)
cmp    $0x7d,%r15d
je     1348 <recv_packet+0x1a8>
cmp    $0x24,%r15d
je     1355 <recv_packet+0x1b5>
cmp    $0x23,%r15d
je     142e <recv_packet+0x28e>
jmp    137c <recv_packet+0x1dc>
movl   $0x1,0x4(%rsp)
jmp    13f1 <recv_packet+0x251>
xor    %eax,%eax
mov    %rax,0x20(%rsp)
movl   $0x0,0x4(%rsp)
xor    %r12d,%r12d
jmp    13f1 <recv_packet+0x251>
xor    %r12d,%r12d
jmp    137c <recv_packet+0x1dc>
mov    %r14d,%edi
mov    %rbx,%rsi
call   10b0 <ungetc@plt>
mov    0x8(%rsp),%rax
mov    0x4(%rsp),%ecx
mov    %r15d,%ebp
xor    $0x20,%ebp
test   %ecx,%ecx
cmove  %r15d,%ebp
mov    0x18(%rsp),%rbx
cmp    %rbx,%r12
jne    13d0 <recv_packet+0x230>
add    %rbx,%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
call   10c0 <realloc@plt>
test   %rax,%rax
mov    %rbx,0x18(%rsp)
jne    13d0 <recv_packet+0x230>
mov    $0x1,%edi
lea    0xc48(%rip),%rsi
call   1090 <err@plt>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
mov    0x10(%rsp),%rbx
mov    %rax,0x8(%rsp)
mov    %ebp,(%rax,%r12,4)
add    $0x1,%r12
movl   $0x0,0x4(%rsp)
mov    0x2bf7(%rip),%rbp
mov    %rbx,%rdi
call   1070 <fgetc@plt>
mov    %eax,%r15d
cmp    0x0(%rbp),%eax
mov    0x20(%rsp),%r14
jne    1256 <recv_packet+0xb6>
jmp    120f <recv_packet+0x6f>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %rax,%rax
je     14a7 <recv_packet+0x307>
lea    0xbed(%rip),%rsi
xor    %edi,%edi
jmp    14b3 <recv_packet+0x313>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <fgetc@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <gdb_decode_hex@plt>
xor    %ecx,%ecx
cmp    %eax,%r14d
sete   %cl
mov    0x28(%rsp),%rax
mov    %ecx,(%rax)
mov    0x30(%rsp),%rax
mov    %r12,(%rax)
cmp    0x18(%rsp),%r12
jne    1498 <recv_packet+0x2f8>
lea    0x1(%r12),%rsi
mov    0x8(%rsp),%rdi
call   10c0 <realloc@plt>
test   %rax,%rax
jne    148e <recv_packet+0x2ee>
lea    0xb85(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
xor    %eax,%eax
movl   $0x0,(%rax,%r12,4)
jmp    14b8 <recv_packet+0x318>
mov    0x8(%rsp),%rax
movl   $0x0,(%rax,%r12,4)
jmp    14b8 <recv_packet+0x318>
lea    0xb7e(%rip),%rsi
mov    $0x1,%edi
call   1050 <errx@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
@EOF = global i32 0
@.str.1 = [8 x i8] c"realloc\00"
@.str.2 = [5 x i8] c"recv\00"
@.str.3 = [24 x i8] c"recv: Connection closed\00"
@.str.4 = [31 x i8] c"recv: Unknown connection error\00"
define i32* @recv_packet(i32* %0, i64* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32* %0, i32** %5
store i64* %1, i64** %6
store i32* %2, i32** %7
store i64 0, i64* %8
store i64 4096, i64* %9
%18 = load i64, i64* %9
%19 = call i32* @malloc(i64 %18)
store i32* %19, i32** %10
%20 = load i32*, i32** %10
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %3
%23 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %3
store i32 0, i32* %12
store i32 0, i32* %13
br label %25
25: ; preds = %35, %24
%26 = load i32*, i32** %5
%27 = call i32 @fgetc(i32* %26)
store i32 %27, i32* %11
%28 = load i32, i32* @EOF
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i32, i32* %11
%32 = icmp ne i32 %31, 36
br label %33
33: ; preds = %30, %25
%34 = phi i1 [ false, %25 ], [ %32, %30 ]
br i1 %34, label %35, label %36
35: ; preds = %33
br label %25
36: ; preds = %33
br label %37
37: ; preds = %166, %125, %83, %47, %36
%38 = load i32*, i32** %5
%39 = call i32 @fgetc(i32* %38)
store i32 %39, i32* %11
%40 = load i32, i32* @EOF
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %172
42: ; preds = %37
%43 = load i32, i32* %11
%44 = load i32, i32* %12
%45 = add nsw i32 %44, %43
store i32 %45, i32* %12
%46 = load i32, i32* %11
switch i32 %46, label %145 [
i32 36, label %47
i32 35, label %48
i32 125, label %83
i32 42, label %84
]
47: ; preds = %42
store i64 0, i64* %8
store i32 0, i32* %12
store i32 0, i32* %13
br label %37
48: ; preds = %42
%49 = load i32, i32* %11
%50 = load i32, i32* %12
%51 = sub nsw i32 %50, %49
store i32 %51, i32* %12
%52 = load i32*, i32** %5
%53 = call i32 @fgetc(i32* %52)
store i32 %53, i32* %14
%54 = load i32*, i32** %5
%55 = call i32 @fgetc(i32* %54)
store i32 %55, i32* %15
%56 = load i32, i32* %12
%57 = load i32, i32* %14
%58 = load i32, i32* %15
%59 = call i32 @gdb_decode_hex(i32 %57, i32 %58)
%60 = icmp eq i32 %56, %59
%61 = zext i1 %60 to i32
%62 = load i32*, i32** %7
store i32 %61, i32* %62
%63 = load i64, i64* %8
%64 = load i64*, i64** %6
store i64 %63, i64* %64
%65 = load i64, i64* %8
%66 = load i64, i64* %9
%67 = icmp eq i64 %65, %66
br i1 %67, label %68, label %78
68: ; preds = %48
%69 = load i32*, i32** %10
%70 = load i64, i64* %9
%71 = add i64 %70, 1
%72 = call i32* @realloc(i32* %69, i64 %71)
store i32* %72, i32** %10
%73 = load i32*, i32** %10
%74 = icmp eq i32* %73, null
br i1 %74, label %75, label %77
75: ; preds = %68
%76 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %77
77: ; preds = %75, %68
br label %78
78: ; preds = %77, %48
%79 = load i32*, i32** %10
%80 = load i64, i64* %8
%81 = getelementptr inbounds i32, i32* %79, i64 %80
store i32 0, i32* %81
%82 = load i32*, i32** %10
store i32* %82, i32** %4
br label %187
83: ; preds = %42
store i32 1, i32* %13
br label %37
84: ; preds = %42
%85 = load i64, i64* %8
%86 = icmp ugt i64 %85, 0
br i1 %86, label %87, label %144
87: ; preds = %84
%88 = load i32*, i32** %5
%89 = call i32 @fgetc(i32* %88)
store i32 %89, i32* %16
%90 = load i32, i32* %16
%91 = icmp slt i32 %90, 29
br i1 %91, label %101, label %92
92: ; preds = %87
%93 = load i32, i32* %16
%94 = icmp sgt i32 %93, 126
br i1 %94, label %101, label %95
95: ; preds = %92
%96 = load i32, i32* %16
%97 = icmp eq i32 %96, 36
br i1 %97, label %101, label %98
98: ; preds = %95
%99 = load i32, i32* %16
%100 = icmp eq i32 %99, 35
br i1 %100, label %101, label %105
101: ; preds = %98, %95, %92, %87
%102 = load i32, i32* %16
%103 = load i32*, i32** %5
%104 = call i32 @ungetc(i32 %102, i32* %103)
br label %143
105: ; preds = %98
%106 = load i32, i32* %16
%107 = sub nsw i32 %106, 29
store i32 %107, i32* %17
%108 = load i64, i64* %8
%109 = load i32, i32* %17
%110 = sext i32 %109 to i64
%111 = add i64 %108, %110
%112 = load i64, i64* %9
%113 = icmp ugt i64 %111, %112
br i1 %113, label %114, label %125
114: ; preds = %105
%115 = load i64, i64* %9
%116 = mul i64 %115, 2
store i64 %116, i64* %9
%117 = load i32*, i32** %10
%118 = load i64, i64* %9
%119 = call i32* @realloc(i32* %117, i64 %118)
store i32* %119, i32** %10
%120 = load i32*, i32** %10
%121 = icmp eq i32* %120, null
br i1 %121, label %122, label %124
122: ; preds = %114
%123 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %124
124: ; preds = %122, %114
br label %125
125: ; preds = %124, %105
%126 = load i32*, i32** %10
%127 = load i64, i64* %8
%128 = getelementptr inbounds i32, i32* %126, i64 %127
%129 = load i32*, i32** %10
%130 = load i64, i64* %8
%131 = sub i64 %130, 1
%132 = getelementptr inbounds i32, i32* %129, i64 %131
%133 = load i32, i32* %132
%134 = load i32, i32* %17
%135 = call i32 @memset(i32* %128, i32 %133, i32 %134)
%136 = load i32, i32* %17
%137 = sext i32 %136 to i64
%138 = load i64, i64* %8
%139 = add i64 %138, %137
store i64 %139, i64* %8
%140 = load i32, i32* %16
%141 = load i32, i32* %12
%142 = add nsw i32 %141, %140
store i32 %142, i32* %12
br label %37
143: ; preds = %101
br label %144
144: ; preds = %143, %84
br label %145
145: ; preds = %144, %42
%146 = load i32, i32* %13
%147 = icmp ne i32 %146, 0
br i1 %147, label %148, label %151
148: ; preds = %145
%149 = load i32, i32* %11
%150 = xor i32 %149, 32
store i32 %150, i32* %11
store i32 0, i32* %13
br label %151
151: ; preds = %148, %145
%152 = load i64, i64* %8
%153 = load i64, i64* %9
%154 = icmp eq i64 %152, %153
br i1 %154, label %155, label %166
155: ; preds = %151
%156 = load i64, i64* %9
%157 = mul i64 %156, 2
store i64 %157, i64* %9
%158 = load i32*, i32** %10
%159 = load i64, i64* %9
%160 = call i32* @realloc(i32* %158, i64 %159)
store i32* %160, i32** %10
%161 = load i32*, i32** %10
%162 = icmp eq i32* %161, null
br i1 %162, label %163, label %165
163: ; preds = %155
%164 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %165
165: ; preds = %163, %155
br label %166
166: ; preds = %165, %151
%167 = load i32, i32* %11
%168 = load i32*, i32** %10
%169 = load i64, i64* %8
%170 = add i64 %169, 1
store i64 %170, i64* %8
%171 = getelementptr inbounds i32, i32* %168, i64 %169
store i32 %167, i32* %171
br label %37
172: ; preds = %37
%173 = load i32*, i32** %5
%174 = call i64 @ferror(i32* %173)
%175 = icmp ne i64 %174, 0
br i1 %175, label %176, label %178
176: ; preds = %172
%177 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %187
178: ; preds = %172
%179 = load i32*, i32** %5
%180 = call i64 @feof(i32* %179)
%181 = icmp ne i64 %180, 0
br i1 %181, label %182, label %184
182: ; preds = %178
%183 = call i32 @errx(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %186
184: ; preds = %178
%185 = call i32 @errx(i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %186
186: ; preds = %184, %182
br label %187
187: ; preds = %78, %186, %176
%188 = load i32*, i32** %4
ret i32* %188
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
@EOF = global i32 0
@.str.1 = [8 x i8] c"realloc\00"
@.str.2 = [5 x i8] c"recv\00"
@.str.3 = [24 x i8] c"recv: Connection closed\00"
@.str.4 = [31 x i8] c"recv: Unknown connection error\00"
define i32* @recv_packet(i32* nocapture %0, i64* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = tail call i32* @malloc(i64 4096)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %3
br label %9
9: ; preds = %8, %9
%10 = tail call i32 @fgetc(i32* %0)
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %10, %11
%13 = icmp ne i32 %10, 36
%14 = and i1 %13, %12
br i1 %14, label %9, label %15
15: ; preds = %9
%16 = tail call i32 @fgetc(i32* %0)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %110, label %19
19: ; preds = %15, %101
%20 = phi i32 [ %107, %101 ], [ %16, %15 ]
%21 = phi i64 [ %106, %101 ], [ 0, %15 ]
%22 = phi i64 [ %105, %101 ], [ 4096, %15 ]
%23 = phi i32* [ %104, %101 ], [ %4, %15 ]
%24 = phi i32 [ %103, %101 ], [ 0, %15 ]
%25 = phi i32 [ %102, %101 ], [ 0, %15 ]
br label %26
26: ; preds = %19, %71
%27 = phi i32 [ %20, %19 ], [ %80, %71 ]
%28 = phi i64 [ %21, %19 ], [ %63, %71 ]
%29 = phi i64 [ %22, %19 ], [ %73, %71 ]
%30 = phi i32* [ %23, %19 ], [ %72, %71 ]
%31 = phi i32 [ %25, %19 ], [ %79, %71 ]
%32 = add nsw i32 %27, %31
switch i32 %27, label %83 [
i32 36, label %101
i32 35, label %33
i32 125, label %100
i32 42, label %49
]
33: ; preds = %26
%34 = tail call i32 @fgetc(i32* %0)
%35 = tail call i32 @fgetc(i32* %0)
%36 = tail call i32 @gdb_decode_hex(i32 %34, i32 %35)
%37 = icmp eq i32 %31, %36
%38 = zext i1 %37 to i32
store i32 %38, i32* %2
store i64 %28, i64* %1
%39 = icmp eq i64 %28, %29
br i1 %39, label %40, label %46
40: ; preds = %33
%41 = add i64 %28, 1
%42 = tail call i32* @realloc(i32* %30, i64 %41)
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %46
46: ; preds = %40, %44, %33
%47 = phi i32* [ null, %44 ], [ %42, %40 ], [ %30, %33 ]
%48 = getelementptr inbounds i32, i32* %47, i64 %28
store i32 0, i32* %48
br label %122
49: ; preds = %26
%50 = icmp eq i64 %28, 0
br i1 %50, label %83, label %51
51: ; preds = %49
%52 = tail call i32 @fgetc(i32* %0)
%53 = add i32 %52, -127
%54 = icmp ult i32 %53, -98
%55 = add i32 %52, -35
%56 = icmp ult i32 %55, 2
%57 = or i1 %56, %54
br i1 %57, label %58, label %60
58: ; preds = %51
%59 = tail call i32 @ungetc(i32 %52, i32* %0)
br label %83
60: ; preds = %51
%61 = add nsw i32 %52, -29
%62 = zext i32 %61 to i64
%63 = add i64 %28, %62
%64 = icmp ugt i64 %63, %29
br i1 %64, label %65, label %71
65: ; preds = %60
%66 = shl i64 %29, 1
%67 = tail call i32* @realloc(i32* %30, i64 %66)
%68 = icmp eq i32* %67, null
br i1 %68, label %69, label %71
69: ; preds = %65
%70 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %71
71: ; preds = %60, %69, %65
%72 = phi i32* [ null, %69 ], [ %67, %65 ], [ %30, %60 ]
%73 = phi i64 [ %66, %69 ], [ %66, %65 ], [ %29, %60 ]
%74 = getelementptr inbounds i32, i32* %72, i64 %28
%75 = add i64 %28, -1
%76 = getelementptr inbounds i32, i32* %72, i64 %75
%77 = load i32, i32* %76
%78 = tail call i32 @memset(i32* %74, i32 %77, i32 %61)
%79 = add nsw i32 %52, %32
%80 = tail call i32 @fgetc(i32* %0)
%81 = load i32, i32* @EOF
%82 = icmp eq i32 %80, %81
br i1 %82, label %110, label %26
83: ; preds = %49, %26, %58
%84 = phi i64 [ %28, %58 ], [ 0, %49 ], [ %28, %26 ]
%85 = icmp eq i32 %24, 0
%86 = xor i32 %27, 32
%87 = select i1 %85, i32 %27, i32 %86
%88 = icmp eq i64 %84, %29
br i1 %88, label %89, label %95
89: ; preds = %83
%90 = shl i64 %29, 1
%91 = tail call i32* @realloc(i32* %30, i64 %90)
%92 = icmp eq i32* %91, null
br i1 %92, label %93, label %95
93: ; preds = %89
%94 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %95
95: ; preds = %89, %93, %83
%96 = phi i32* [ null, %93 ], [ %91, %89 ], [ %30, %83 ]
%97 = phi i64 [ %90, %93 ], [ %90, %89 ], [ %29, %83 ]
%98 = add i64 %84, 1
%99 = getelementptr inbounds i32, i32* %96, i64 %84
store i32 %87, i32* %99
br label %101
100: ; preds = %26
br label %101
101: ; preds = %26, %100, %95
%102 = phi i32 [ %32, %95 ], [ %32, %100 ], [ 0, %26 ]
%103 = phi i32 [ 0, %95 ], [ 1, %100 ], [ 0, %26 ]
%104 = phi i32* [ %96, %95 ], [ %30, %100 ], [ %30, %26 ]
%105 = phi i64 [ %97, %95 ], [ %29, %100 ], [ %29, %26 ]
%106 = phi i64 [ %98, %95 ], [ %28, %100 ], [ 0, %26 ]
%107 = tail call i32 @fgetc(i32* %0)
%108 = load i32, i32* @EOF
%109 = icmp eq i32 %107, %108
br i1 %109, label %110, label %19
110: ; preds = %101, %71, %15
%111 = tail call i64 @ferror(i32* %0)
%112 = icmp eq i64 %111, 0
br i1 %112, label %115, label %113
113: ; preds = %110
%114 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %122
115: ; preds = %110
%116 = tail call i64 @feof(i32* %0)
%117 = icmp eq i64 %116, 0
br i1 %117, label %120, label %118
118: ; preds = %115
%119 = tail call i32 @errx(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %122
120: ; preds = %115
%121 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %122
122: ; preds = %113, %120, %118, %46
%123 = phi i32* [ %47, %46 ], [ undef, %118 ], [ undef, %120 ], [ undef, %113 ]
ret i32* %123
}