#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_zero;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char const *);
int findHops(char *server, int serverport, char **hops) {
  int depSocket;
  char buffer[1024], num_int[5];
  struct sockaddr_in serverAddr;
  socklen_t addr_size;
  const char s[2] = ",";
  const char s2[2] = "<";
  const char s3[2] = ">";
  const char s4[2] = ";";
  if (1)
    printf("Connecting to %s:%d\n", server, serverport);
  depSocket = socket(AF_INET, SOCK_STREAM, 0);
  serverAddr.sin_family = AF_INET;
  serverAddr.sin_port = htons(serverport);
  serverAddr.sin_addr.s_addr = inet_addr(server);
  memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);
  addr_size = sizeof serverAddr;
  int result = connect(depSocket, (struct sockaddr *)&serverAddr, addr_size);
  strcpy(buffer, "rdall node,*\n");
  send(depSocket, buffer, 512, 0);
  bzero(buffer, 512);
  char *temp = (char *)malloc(sizeof(char) * 50);
  int i, size;
  while (recv(depSocket, buffer, 512, 0)) {
    if (1)
      printf("Receiving on REGISTERDEP %s\n", buffer);
    sscanf(strtok(buffer, s), "%d", &size);
    if (1)
      printf("REGISTERDEP size: %d\n", size);
    for (i = 0; i < size; i++) {
      strcpy(hops[i], strtok(NULL, s));
      if (1)
        printf("REGISTERDEP hop: %d->%s\n", i, hops[i]);
    }
    bzero(buffer, 512);
  }
  return i;
}


x86 assembly (clang, -O0):
<findHops>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0xe13(%rip),%ax
mov    %ax,-0x43e(%rbp)
mov    0xe07(%rip),%ax
mov    %ax,-0x440(%rbp)
mov    0xdfb(%rip),%ax
mov    %ax,-0x442(%rbp)
mov    0xdef(%rip),%ax
mov    %ax,-0x444(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x42c(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x430(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x434(%rbp)
mov    -0x438(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
movl   $0x10,-0x43c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x438(%rbp),%rsi
mov    -0x43c(%rbp),%edx
call   10e0 <connect@plt>
mov    %eax,-0x448(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xd5d(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x1c(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
lea    -0x420(%rbp),%rdi
mov    $0x200,%esi
call   10d0 <bzero@plt>
mov    $0x32,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x450(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
je     140d <findHops+0x23d>
lea    -0x420(%rbp),%rsi
lea    0xd00(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x420(%rbp),%rdi
lea    -0x43e(%rbp),%rsi
call   10c0 <strtok@plt>
mov    %rax,%rdi
lea    0xcf9(%rip),%rsi
lea    -0x458(%rbp),%rdx
call   10b0 <sscanf@plt>
mov    -0x458(%rbp),%esi
lea    0xce3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x454(%rbp)
mov    -0x454(%rbp),%eax
cmp    -0x458(%rbp),%eax
jge    13f7 <findHops+0x227>
mov    -0x18(%rbp),%rax
movslq -0x454(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x460(%rbp)
lea    -0x43e(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <strtok@plt>
mov    -0x460(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x454(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0x454(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xc85(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x454(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x454(%rbp)
jmp    1379 <findHops+0x1a9>
lea    -0x420(%rbp),%rdi
mov    $0x200,%esi
call   10d0 <bzero@plt>
jmp    12fd <findHops+0x12d>
mov    -0x454(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findHops>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rdx,%rbx
mov    %esi,%r12d
mov    %rdi,%r14
movw   $0x2c,0xa(%rsp)
lea    0xe08(%rip),%rdi
mov    %r14,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2ddc(%rip),%r15
mov    (%r15),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebp
mov    (%r15),%eax
mov    %eax,0x1c(%rsp)
mov    %r12d,%edi
call   1050 <htons@plt>
mov    %eax,0x18(%rsp)
mov    %r14,%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x14(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x10,%edx
call   10e0 <connect@plt>
lea    0xdb1(%rip),%rsi
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %r14,%rdi
mov    $0x200,%esi
call   10d0 <bzero@plt>
mov    $0x32,%edi
call   10a0 <malloc@plt>
mov    %ebp,0xc(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
je     138d <findHops+0x1bd>
lea    0x20(%rsp),%r12
lea    0xa(%rsp),%rbp
lea    0xd91(%rip),%r14
jmp    12f9 <findHops+0x129>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x200,%esi
call   10d0 <bzero@plt>
mov    0xc(%rsp),%edi
mov    %r12,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
je     138d <findHops+0x1bd>
lea    0xd23(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   10c0 <strtok@plt>
mov    %rax,%rdi
lea    0xd21(%rip),%rsi
lea    0x4(%rsp),%rdx
call   10b0 <sscanf@plt>
mov    0x4(%rsp),%esi
lea    0xd0f(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cmpl   $0x0,0x4(%rsp)
mov    $0x0,%r13d
jle    12d0 <findHops+0x100>
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
mov    (%rbx,%r13,8),%r15
xor    %edi,%edi
mov    %rbp,%rsi
call   10c0 <strtok@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    (%rbx,%r13,8),%rdx
mov    %r14,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%r13
movslq 0x4(%rsp),%rax
cmp    %rax,%r13
jl     1350 <findHops+0x180>
jmp    12d0 <findHops+0x100>
mov    %r13d,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.findHops.s = [2 x i8] c",\00"
@__const.findHops.s2 = [2 x i8] c"<\00"
@__const.findHops.s3 = [2 x i8] c">\00"
@__const.findHops.s4 = [2 x i8] c";\00"
@.str = [21 x i8] c"Connecting to %s:%d\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [14 x i8] c"rdall node,*\0A\00"
@.str.2 = [29 x i8] c"Receiving on REGISTERDEP %s\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [22 x i8] c"REGISTERDEP size: %d\0A\00"
@.str.5 = [25 x i8] c"REGISTERDEP hop: %d->%s\0A\00"
define i32 @findHops(i8* %0, i32 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca [5 x i8]
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca [2 x i8]
%13 = alloca [2 x i8]
%14 = alloca [2 x i8]
%15 = alloca [2 x i8]
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
%20 = bitcast [2 x i8]* %12 to i8*
%21 = bitcast [2 x i8]* %13 to i8*
%22 = bitcast [2 x i8]* %14 to i8*
%23 = bitcast [2 x i8]* %15 to i8*
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %24, i32 %25)
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_STREAM
%29 = call i32 @socket(i32 %27, i32 %28, i32 0)
store i32 %29, i32* %7
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 3
store i32 %30, i32* %31
%32 = load i32, i32* %5
%33 = call i32 @htons(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %33, i32* %34
%35 = load i8*, i8** %4
%36 = call i32 @inet_addr(i8* %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%38 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %37, i32 0, i32 0
store i32 %36, i32* %38
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 @memset(i32 %40, i8 signext 0, i32 4)
store i32 16, i32* %11
%42 = load i32, i32* %7
%43 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%44 = load i32, i32* %11
%45 = call i32 @connect(i32 %42, %struct.sockaddr* %43, i32 %44)
store i32 %45, i32* %16
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%47 = call i32 @strcpy(i8* %46, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%48 = load i32, i32* %7
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%50 = call i32 @send(i32 %48, i8* %49, i32 512, i32 0)
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%52 = call i32 @bzero(i8* %51, i32 512)
%53 = call i64 @malloc(i32 50)
%54 = inttoptr i64 %53 to i8*
store i8* %54, i8** %17
br label %55
55: ; preds = %92, %3
%56 = load i32, i32* %7
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%58 = call i64 @recv(i32 %56, i8* %57, i32 512, i32 0)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %95
60: ; preds = %55
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %61)
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%64 = getelementptr inbounds [2 x i8], [2 x i8]* %12, i64 0, i64 0
%65 = call i8* @strtok(i8* %63, i8* %64)
%66 = call i32 @sscanf(i8* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %19)
%67 = load i32, i32* %19
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %67)
store i32 0, i32* %18
br label %69
69: ; preds = %89, %60
%70 = load i32, i32* %18
%71 = load i32, i32* %19
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %92
73: ; preds = %69
%74 = load i8**, i8*** %6
%75 = load i32, i32* %18
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8*, i8** %74, i64 %76
%78 = load i8*, i8** %77
%79 = getelementptr inbounds [2 x i8], [2 x i8]* %12, i64 0, i64 0
%80 = call i8* @strtok(i8* null, i8* %79)
%81 = call i32 @strcpy(i8* %78, i8* %80)
%82 = load i32, i32* %18
%83 = load i8**, i8*** %6
%84 = load i32, i32* %18
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8*, i8** %83, i64 %85
%87 = load i8*, i8** %86
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %82, i8* %87)
br label %89
89: ; preds = %73
%90 = load i32, i32* %18
%91 = add nsw i32 %90, 1
store i32 %91, i32* %18
br label %69
92: ; preds = %69
%93 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%94 = call i32 @bzero(i8* %93, i32 512)
br label %55
95: ; preds = %55
%96 = load i32, i32* %18
ret i32 %96
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"Connecting to %s:%d\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [14 x i8] c"rdall node,*\0A\00"
@.str.2 = [29 x i8] c"Receiving on REGISTERDEP %s\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [22 x i8] c"REGISTERDEP size: %d\0A\00"
@.str.5 = [25 x i8] c"REGISTERDEP hop: %d->%s\0A\00"
define i32 @findHops(i8* %0, i32 %1, i8** nocapture %2) {
%4 = alloca [1024 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca i16
%7 = alloca i32
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = bitcast i16* %6 to i8*
store i16 44, i16* %6
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 3
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 %1)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %17, i32* %18
%19 = tail call i32 @inet_addr(i8* %0)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %19, i32* %20
%21 = tail call i32 @memset(i32 undef, i8 signext 0, i32 4)
%22 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%23 = call i32 @connect(i32 %14, %struct.sockaddr* %22, i32 16)
%24 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @send(i32 %14, i8* %8, i32 512, i32 0)
%26 = call i32 @bzero(i8* %8, i32 512)
%27 = call i64 @malloc(i32 50)
%28 = bitcast i32* %7 to i8*
%29 = call i64 @recv(i32 %14, i8* %8, i32 512, i32 0)
%30 = icmp eq i64 %29, 0
br i1 %30, label %59, label %31
31: ; preds = %3, %54
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%33 = call i8* @strtok(i8* %8, i8* %10)
%34 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%35 = load i32, i32* %7
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %7
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %54
39: ; preds = %31, %39
%40 = phi i64 [ %48, %39 ], [ 0, %31 ]
%41 = getelementptr inbounds i8*, i8** %2, i64 %40
%42 = load i8*, i8** %41
%43 = call i8* @strtok(i8* null, i8* %10)
%44 = call i32 @strcpy(i8* %42, i8* %43)
%45 = load i8*, i8** %41
%46 = trunc i64 %40 to i32
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %46, i8* %45)
%48 = add nuw nsw i64 %40, 1
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = icmp slt i64 %48, %50
br i1 %51, label %39, label %52
52: ; preds = %39
%53 = trunc i64 %48 to i32
br label %54
54: ; preds = %52, %31
%55 = phi i32 [ 0, %31 ], [ %53, %52 ]
%56 = call i32 @bzero(i8* %8, i32 512)
%57 = call i64 @recv(i32 %14, i8* %8, i32 512, i32 0)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %31
59: ; preds = %54, %3
%60 = phi i32 [ undef, %3 ], [ %55, %54 ]
ret i32 %60
}