#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 */
char *calloc(int, int);
int /*<<< orphan*/ eof_va_read(int, int, int, char *, int, char *);
int /*<<< orphan*/ eof_va_write(int, int, int, char *, int, char *, int,
                                char *);
scalar_t__ errno;
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int read_all(int, char *, int);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int strtoul(char *, int /*<<< orphan*/ *, int);
int eof_ui_peer_show(int sockfd, char errmsg[128], char nick[128],
                     char keyid[40], char **addrs) {
  char *p;
  int i, noa;
  char cmd[4 + 1];
  char size[6 + 1];
  char id[6 + 1];
  memset(cmd, 0, 4 + 1);
  memset(size, 0, 6 + 1);
  memset(id, 0, 6 + 1);
  if (!eof_va_write(sockfd, 3, 4, "2105", 6, id, 128, nick)) {
    return -1;
  }
  if (!eof_va_read(sockfd, 2, 4, cmd, 6, id)) {
    return -1;
  }
  if (strncmp(cmd, "1105", 4)) {
    printf("returned cmd=%s (should be %s)\n", cmd, "1105");
    errno = 0;
    read_all(sockfd, errmsg, 128);
    return -1;
  }
  if (!eof_va_read(sockfd, 2, 40, keyid, 6, size)) {
    return -1;
  }
  noa = strtoul(size, NULL, 10);
  printf("Addresses reported from EOFi: %d\n", noa);
  *addrs = calloc(noa, 128 + 1);
  if (!(*addrs)) {
    strncpy(errmsg, "calloc()", 128);
    return -1;
  }
  for (i = 0; i < noa; i++) {
    p = *addrs + (i * (128 + 1));
    if (read_all(sockfd, p, 128) != 128) {
      return -1;
    }
  }
  printf("Addresses before end / from EOFi: %d\n", noa);
  return noa;
}


x86 assembly (clang, -O0):
<eof_ui_peer_show>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
lea    -0x3d(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1060 <memset@plt>
lea    -0x44(%rbp),%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1060 <memset@plt>
lea    -0x4b(%rbp),%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x4b(%rbp),%r9
mov    -0x18(%rbp),%rax
mov    $0x3,%esi
mov    $0x4,%edx
lea    0xe09(%rip),%rcx
mov    $0x6,%r8d
movl   $0x80,(%rsp)
mov    %rax,0x8(%rsp)
call   10a0 <eof_va_write@plt>
cmp    $0x0,%eax
jne    1223 <eof_ui_peer_show+0x93>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d9 <eof_ui_peer_show+0x249>
mov    -0x8(%rbp),%edi
lea    -0x3d(%rbp),%rcx
lea    -0x4b(%rbp),%r9
mov    $0x2,%esi
mov    $0x4,%edx
mov    $0x6,%r8d
call   1080 <eof_va_read@plt>
cmp    $0x0,%eax
jne    1258 <eof_ui_peer_show+0xc8>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d9 <eof_ui_peer_show+0x249>
lea    -0x3d(%rbp),%rdi
lea    0xda2(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     12bb <eof_ui_peer_show+0x12b>
lea    -0x3d(%rbp),%rsi
lea    0xd88(%rip),%rdi
lea    0xd7c(%rip),%rdx
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d49(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x80,%edx
call   10b0 <read_all@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d9 <eof_ui_peer_show+0x249>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rcx
lea    -0x44(%rbp),%r9
mov    $0x2,%esi
mov    $0x28,%edx
mov    $0x6,%r8d
call   1080 <eof_va_read@plt>
cmp    $0x0,%eax
jne    12f0 <eof_ui_peer_show+0x160>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d9 <eof_ui_peer_show+0x249>
lea    -0x44(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1090 <strtoul@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%esi
lea    0xd1b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%edi
mov    $0x81,%esi
call   1070 <calloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    135c <eof_ui_peer_show+0x1cc>
mov    -0x10(%rbp),%rdi
lea    0xd06(%rip),%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d9 <eof_ui_peer_show+0x249>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    13c2 <eof_ui_peer_show+0x232>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
imul   $0x81,-0x34(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    $0x80,%edx
call   10b0 <read_all@plt>
cmp    $0x80,%eax
je     13af <eof_ui_peer_show+0x21f>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d9 <eof_ui_peer_show+0x249>
jmp    13b4 <eof_ui_peer_show+0x224>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1363 <eof_ui_peer_show+0x1d3>
mov    -0x38(%rbp),%esi
lea    0xc89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eof_ui_peer_show>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r15
mov    %rcx,%r13
mov    %rdx,%rbp
mov    %rsi,0x18(%rsp)
mov    %edi,%r14d
lea    0xc(%rsp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1060 <memset@plt>
lea    0x11(%rsp),%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1060 <memset@plt>
lea    0x21(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1060 <memset@plt>
lea    0xe14(%rip),%rcx
mov    %r14d,%edi
mov    $0x3,%esi
mov    $0x4,%edx
mov    $0x6,%r8d
mov    %rbx,%r9
push   %rbp
push   $0x80
call   10a0 <eof_va_write@plt>
add    $0x10,%rsp
mov    $0xffffffff,%r12d
test   %eax,%eax
je     1296 <eof_ui_peer_show+0x106>
lea    0xc(%rsp),%rcx
lea    0x21(%rsp),%r9
mov    %r14d,%edi
mov    $0x2,%esi
mov    $0x4,%edx
mov    $0x6,%r8d
call   1080 <eof_va_read@plt>
test   %eax,%eax
je     1296 <eof_ui_peer_show+0x106>
lea    0xdbd(%rip),%rsi
lea    0xc(%rsp),%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     12a8 <eof_ui_peer_show+0x118>
lea    0xda7(%rip),%rdi
lea    0xd9b(%rip),%rdx
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d63(%rip),%rax
movq   $0x0,(%rax)
mov    %r14d,%edi
mov    0x18(%rsp),%rsi
mov    $0x80,%edx
call   10b0 <read_all@plt>
mov    %r12d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x11(%rsp),%r9
mov    %r14d,%edi
mov    $0x2,%esi
mov    $0x28,%edx
mov    %r13,%rcx
mov    $0x6,%r8d
call   1080 <eof_va_read@plt>
test   %eax,%eax
je     1296 <eof_ui_peer_show+0x106>
lea    0x11(%rsp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1090 <strtoul@plt>
mov    %eax,%r13d
lea    0xd43(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13d,%edi
mov    $0x81,%esi
call   1070 <calloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1376 <eof_ui_peer_show+0x1e6>
test   %r13d,%r13d
jle    1391 <eof_ui_peer_show+0x201>
mov    %r14d,%edi
mov    %rax,%rsi
mov    $0x80,%edx
call   10b0 <read_all@plt>
cmp    $0x80,%eax
jne    1296 <eof_ui_peer_show+0x106>
mov    %r13d,%eax
mov    %rax,%rbx
shl    $0x7,%rbx
add    %rax,%rbx
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
lea    0x81(%rcx),%rbp
cmp    %rbp,%rbx
je     1391 <eof_ui_peer_show+0x201>
mov    (%r15),%rax
lea    (%rax,%rcx,1),%rsi
add    $0x81,%rsi
mov    %r14d,%edi
mov    $0x80,%edx
call   10b0 <read_all@plt>
mov    %rbp,%rcx
cmp    $0x80,%eax
je     1340 <eof_ui_peer_show+0x1b0>
jmp    1296 <eof_ui_peer_show+0x106>
lea    0xccf(%rip),%rsi
mov    0x18(%rsp),%rdi
mov    $0x80,%edx
call   1030 <strncpy@plt>
jmp    1296 <eof_ui_peer_show+0x106>
lea    0xcbd(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13d,%r12d
jmp    1296 <eof_ui_peer_show+0x106>

LLVM IR (-O0):
@.str = [5 x i8] c"2105\00"
@.str.1 = [5 x i8] c"1105\00"
@.str.2 = [32 x i8] c"returned cmd=%s (should be %s)\0A\00"
@errno = global i64 0
@.str.3 = [34 x i8] c"Addresses reported from EOFi: %d\0A\00"
@.str.4 = [9 x i8] c"calloc()\00"
@.str.5 = [38 x i8] c"Addresses before end / from EOFi: %d\0A\00"
define i32 @eof_ui_peer_show(i32 %0, i8* %1, i8* %2, i8* %3, i8** %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8**
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca [5 x i8]
%16 = alloca [7 x i8]
%17 = alloca [7 x i8]
store i32 %0, i32* %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8** %4, i8*** %11
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %15, i64 0, i64 0
%19 = call i32 @memset(i8* %18, i32 0, i32 5)
%20 = getelementptr inbounds [7 x i8], [7 x i8]* %16, i64 0, i64 0
%21 = call i32 @memset(i8* %20, i32 0, i32 7)
%22 = getelementptr inbounds [7 x i8], [7 x i8]* %17, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 7)
%24 = load i32, i32* %7
%25 = getelementptr inbounds [7 x i8], [7 x i8]* %17, i64 0, i64 0
%26 = load i8*, i8** %9
%27 = call i32 @eof_va_write(i32 %24, i32 3, i32 4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 6, i8* %25, i32 128, i8* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %5
store i32 -1, i32* %6
br label %93
30: ; preds = %5
%31 = load i32, i32* %7
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %15, i64 0, i64 0
%33 = getelementptr inbounds [7 x i8], [7 x i8]* %17, i64 0, i64 0
%34 = call i32 @eof_va_read(i32 %31, i32 2, i32 4, i8* %32, i32 6, i8* %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %30
store i32 -1, i32* %6
br label %93
37: ; preds = %30
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %15, i64 0, i64 0
%39 = call i64 @strncmp(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %37
%42 = getelementptr inbounds [5 x i8], [5 x i8]* %15, i64 0, i64 0
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i64 0, i64* @errno
%44 = load i32, i32* %7
%45 = load i8*, i8** %8
%46 = call i32 @read_all(i32 %44, i8* %45, i32 128)
store i32 -1, i32* %6
br label %93
47: ; preds = %37
%48 = load i32, i32* %7
%49 = load i8*, i8** %10
%50 = getelementptr inbounds [7 x i8], [7 x i8]* %16, i64 0, i64 0
%51 = call i32 @eof_va_read(i32 %48, i32 2, i32 40, i8* %49, i32 6, i8* %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %54, label %53
53: ; preds = %47
store i32 -1, i32* %6
br label %93
54: ; preds = %47
%55 = getelementptr inbounds [7 x i8], [7 x i8]* %16, i64 0, i64 0
%56 = call i32 @strtoul(i8* %55, i32* null, i32 10)
store i32 %56, i32* %14
%57 = load i32, i32* %14
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %14
%60 = call i8* @calloc(i32 %59, i32 129)
%61 = load i8**, i8*** %11
store i8* %60, i8** %61
%62 = load i8**, i8*** %11
%63 = load i8*, i8** %62
%64 = icmp ne i8* %63, null
br i1 %64, label %68, label %65
65: ; preds = %54
%66 = load i8*, i8** %8
%67 = call i32 @strncpy(i8* %66, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 128)
store i32 -1, i32* %6
br label %93
68: ; preds = %54
store i32 0, i32* %13
br label %69
69: ; preds = %86, %68
%70 = load i32, i32* %13
%71 = load i32, i32* %14
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %89
73: ; preds = %69
%74 = load i8**, i8*** %11
%75 = load i8*, i8** %74
%76 = load i32, i32* %13
%77 = mul nsw i32 %76, 129
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %75, i64 %78
store i8* %79, i8** %12
%80 = load i32, i32* %7
%81 = load i8*, i8** %12
%82 = call i32 @read_all(i32 %80, i8* %81, i32 128)
%83 = icmp ne i32 %82, 128
br i1 %83, label %84, label %85
84: ; preds = %73
store i32 -1, i32* %6
br label %93
85: ; preds = %73
br label %86
86: ; preds = %85
%87 = load i32, i32* %13
%88 = add nsw i32 %87, 1
store i32 %88, i32* %13
br label %69
89: ; preds = %69
%90 = load i32, i32* %14
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %90)
%92 = load i32, i32* %14
store i32 %92, i32* %6
br label %93
93: ; preds = %89, %84, %65, %53, %41, %36, %29
%94 = load i32, i32* %6
ret i32 %94
}

LLVM IR (-O2):
@.str = [5 x i8] c"2105\00"
@.str.1 = [5 x i8] c"1105\00"
@.str.2 = [32 x i8] c"returned cmd=%s (should be %s)\0A\00"
@errno = global i64 0
@.str.3 = [34 x i8] c"Addresses reported from EOFi: %d\0A\00"
@.str.4 = [9 x i8] c"calloc()\00"
@.str.5 = [38 x i8] c"Addresses before end / from EOFi: %d\0A\00"
define i32 @eof_ui_peer_show(i32 %0, i8* %1, i8* %2, i8* %3, i8** nocapture %4) {
%6 = alloca [5 x i8]
%7 = alloca [7 x i8]
%8 = alloca [7 x i8]
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%11 = getelementptr inbounds [7 x i8], [7 x i8]* %8, i64 0, i64 0
%12 = call i32 @memset(i8* %9, i32 0, i32 5)
%13 = call i32 @memset(i8* %10, i32 0, i32 7)
%14 = call i32 @memset(i8* %11, i32 0, i32 7)
%15 = call i32 @eof_va_write(i32 %0, i32 3, i32 4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 6, i8* %11, i32 128, i8* %2)
%16 = icmp eq i32 %15, 0
br i1 %16, label %54, label %17
17: ; preds = %5
%18 = call i32 @eof_va_read(i32 %0, i32 2, i32 4, i8* %9, i32 6, i8* %11)
%19 = icmp eq i32 %18, 0
br i1 %19, label %54, label %20
20: ; preds = %17
%21 = call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i64 0, i64* @errno
%25 = call i32 @read_all(i32 %0, i8* %1, i32 128)
br label %54
26: ; preds = %20
%27 = call i32 @eof_va_read(i32 %0, i32 2, i32 40, i8* %3, i32 6, i8* %10)
%28 = icmp eq i32 %27, 0
br i1 %28, label %54, label %29
29: ; preds = %26
%30 = call i32 @strtoul(i8* nocapture %10, i32* null, i32 10)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = call i8* @calloc(i32 %30, i32 129)
store i8* %32, i8** %4
%33 = icmp eq i8* %32, null
br i1 %33, label %40, label %34
34: ; preds = %29
%35 = icmp sgt i32 %30, 0
br i1 %35, label %36, label %52
36: ; preds = %34
%37 = zext i32 %30 to i64
%38 = call i32 @read_all(i32 %0, i8* %32, i32 128)
%39 = icmp eq i32 %38, 128
br i1 %39, label %42, label %54
40: ; preds = %29
%41 = call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 128)
br label %54
42: ; preds = %36, %45
%43 = phi i64 [ %51, %45 ], [ 1, %36 ]
%44 = icmp eq i64 %43, %37
br i1 %44, label %52, label %45
45: ; preds = %42
%46 = load i8*, i8** %4
%47 = mul nuw nsw i64 %43, 129
%48 = getelementptr inbounds i8, i8* %46, i64 %47
%49 = call i32 @read_all(i32 %0, i8* %48, i32 128)
%50 = icmp eq i32 %49, 128
%51 = add nuw nsw i64 %43, 1
br i1 %50, label %42, label %54
52: ; preds = %42, %34
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %30)
br label %54
54: ; preds = %45, %36, %26, %17, %5, %52, %40, %23
%55 = phi i32 [ -1, %23 ], [ %30, %52 ], [ -1, %40 ], [ -1, %5 ], [ -1, %17 ], [ -1, %26 ], [ -1, %36 ], [ -1, %45 ]
ret i32 %55
}