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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int atoi(char *);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void deserialize_sockaddr(struct sockaddr *address, char *recv_buf,
                          char *msg_buf) {
  struct sockaddr_in remote_addr;
  char remoteip[16];
  char buf[10];
  int remoteport;
  int start_index = 0;
  int cur_index = 0;
  memset(remoteip, 0, strlen(remoteip));
  memset(buf, 0, strlen(buf));
  for (cur_index; cur_index < strlen(recv_buf); cur_index++) {
    if (recv_buf[cur_index] == ',')
      break;
  }
  strncpy(remoteip, recv_buf + start_index, cur_index - start_index);
  remoteip[cur_index - start_index] = '\0';
  start_index = cur_index + 1;
  cur_index = start_index;
  for (cur_index; cur_index < strlen(recv_buf); cur_index++) {
    if (recv_buf[cur_index] == ',')
      break;
  }
  strncpy(buf, recv_buf + start_index, cur_index - start_index);
  buf[cur_index - start_index];
  remoteport = atoi(buf);
  start_index = cur_index + 1;
  strncpy(msg_buf, recv_buf + start_index, strlen(recv_buf) - start_index);
  msg_buf[strlen(recv_buf) - start_index] = '\0';
  remote_addr.sin_family = AF_INET;
  remote_addr.sin_addr.s_addr = inet_addr(remoteip);
  remote_addr.sin_port = remoteport;
  address = (struct sockaddr *)&remote_addr;
  return;
}


x86 assembly (clang, -O0):
<deserialize_sockaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    -0x4a(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x4a(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x58(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
cmp    %ecx,%eax
jge    11fa <deserialize_sockaddr+0xaa>
mov    -0x10(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    11e7 <deserialize_sockaddr+0x97>
jmp    11fa <deserialize_sockaddr+0xaa>
jmp    11ec <deserialize_sockaddr+0x9c>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11b1 <deserialize_sockaddr+0x61>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x54(%rbp),%rax
add    %rax,%rsi
mov    -0x58(%rbp),%edx
sub    -0x54(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x58(%rbp),%eax
sub    -0x54(%rbp),%eax
cltq
movb   $0x0,-0x40(%rbp,%rax,1)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%eax
cmp    %ecx,%eax
jge    1279 <deserialize_sockaddr+0x129>
mov    -0x10(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    1266 <deserialize_sockaddr+0x116>
jmp    1279 <deserialize_sockaddr+0x129>
jmp    126b <deserialize_sockaddr+0x11b>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1230 <deserialize_sockaddr+0xe0>
lea    -0x4a(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x54(%rbp),%rax
add    %rax,%rsi
mov    -0x58(%rbp),%edx
sub    -0x54(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0x4a(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x50(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x80(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
sub    -0x54(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x78(%rbp),%rax
sub    -0x54(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2ce0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    -0x50(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deserialize_sockaddr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rsp,%r12
mov    %r12,%rdi
call   1040 <strlen@plt>
xor    %r13d,%r13d
mov    %r12,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <memset@plt>
lea    0x16(%rsp),%r12
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11ba <deserialize_sockaddr+0x7a>
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0x2c,(%r15,%r13,1)
je     11ba <deserialize_sockaddr+0x7a>
add    $0x1,%r13
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%r13
jl     11a0 <deserialize_sockaddr+0x60>
mov    %rsp,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1030 <strncpy@plt>
mov    %r13d,%r12d
movb   $0x0,(%rsp,%r12,1)
add    $0x1,%r13d
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %r13d,%ebx
cmp    %eax,%r13d
jge    1207 <deserialize_sockaddr+0xc7>
add    $0x1,%r12
mov    %r12,%rbx
nopl   0x0(%rax,%rax,1)
cmpb   $0x2c,(%r15,%rbx,1)
je     1207 <deserialize_sockaddr+0xc7>
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    %ebx,%eax
jg     11f0 <deserialize_sockaddr+0xb0>
mov    %r13d,%esi
add    %r15,%rsi
mov    %ebx,%edx
sub    %r13d,%edx
lea    0x16(%rsp),%rdi
call   1030 <strncpy@plt>
mov    %ebx,%eax
add    $0x1,%ebx
lea    (%rax,%r15,1),%r12
add    $0x1,%r12
mov    %r15,%rdi
call   1040 <strlen@plt>
sub    %ebx,%eax
mov    %r14,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
sub    %ebx,%eax
cltq
movb   $0x0,(%r14,%rax,1)
mov    %rsp,%rdi
call   1060 <inet_addr@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
define void @deserialize_sockaddr(%struct.sockaddr* %0, i8* %1, i8* %2) {
%4 = alloca %struct.sockaddr*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.sockaddr_in
%8 = alloca [16 x i8]
%9 = alloca [10 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %11
store i32 0, i32* %12
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @memset(i8* %13, i32 0, i32 %15)
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @memset(i8* %17, i32 0, i32 %19)
%21 = load i32, i32* %12
br label %22
22: ; preds = %37, %3
%23 = load i32, i32* %12
%24 = load i8*, i8** %5
%25 = call i32 @strlen(i8* %24)
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %40
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = load i32, i32* %12
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 44
br i1 %34, label %35, label %36
35: ; preds = %27
br label %40
36: ; preds = %27
br label %37
37: ; preds = %36
%38 = load i32, i32* %12
%39 = add nsw i32 %38, 1
store i32 %39, i32* %12
br label %22
40: ; preds = %35, %22
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%42 = load i8*, i8** %5
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i32, i32* %12
%47 = load i32, i32* %11
%48 = sub nsw i32 %46, %47
%49 = call i32 @strncpy(i8* %41, i8* %45, i32 %48)
%50 = load i32, i32* %12
%51 = load i32, i32* %11
%52 = sub nsw i32 %50, %51
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 %53
store i8 0, i8* %54
%55 = load i32, i32* %12
%56 = add nsw i32 %55, 1
store i32 %56, i32* %11
%57 = load i32, i32* %11
store i32 %57, i32* %12
%58 = load i32, i32* %12
br label %59
59: ; preds = %74, %40
%60 = load i32, i32* %12
%61 = load i8*, i8** %5
%62 = call i32 @strlen(i8* %61)
%63 = icmp slt i32 %60, %62
br i1 %63, label %64, label %77
64: ; preds = %59
%65 = load i8*, i8** %5
%66 = load i32, i32* %12
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 44
br i1 %71, label %72, label %73
72: ; preds = %64
br label %77
73: ; preds = %64
br label %74
74: ; preds = %73
%75 = load i32, i32* %12
%76 = add nsw i32 %75, 1
store i32 %76, i32* %12
br label %59
77: ; preds = %72, %59
%78 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%79 = load i8*, i8** %5
%80 = load i32, i32* %11
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %79, i64 %81
%83 = load i32, i32* %12
%84 = load i32, i32* %11
%85 = sub nsw i32 %83, %84
%86 = call i32 @strncpy(i8* %78, i8* %82, i32 %85)
%87 = load i32, i32* %12
%88 = load i32, i32* %11
%89 = sub nsw i32 %87, %88
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 %90
%92 = load i8, i8* %91
%93 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%94 = call i32 @atoi(i8* %93)
store i32 %94, i32* %10
%95 = load i32, i32* %12
%96 = add nsw i32 %95, 1
store i32 %96, i32* %11
%97 = load i8*, i8** %6
%98 = load i8*, i8** %5
%99 = load i32, i32* %11
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i8, i8* %98, i64 %100
%102 = load i8*, i8** %5
%103 = call i32 @strlen(i8* %102)
%104 = load i32, i32* %11
%105 = sub nsw i32 %103, %104
%106 = call i32 @strncpy(i8* %97, i8* %101, i32 %105)
%107 = load i8*, i8** %6
%108 = load i8*, i8** %5
%109 = call i32 @strlen(i8* %108)
%110 = load i32, i32* %11
%111 = sub nsw i32 %109, %110
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i8, i8* %107, i64 %112
store i8 0, i8* %113
%114 = load i32, i32* @AF_INET
%115 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %114, i32* %115
%116 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%117 = call i32 @inet_addr(i8* %116)
%118 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%119 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %118, i32 0, i32 0
store i32 %117, i32* %119
%120 = load i32, i32* %10
%121 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %120, i32* %121
%122 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
store %struct.sockaddr* %122, %struct.sockaddr** %4
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
define void @deserialize_sockaddr(%struct.sockaddr* nocapture readnone %0, i8* %1, i8* %2) {
%4 = alloca [16 x i8]
%5 = alloca [10 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%8 = call i32 @strlen(i8* %6)
%9 = call i32 @memset(i8* %6, i32 0, i32 %8)
%10 = call i32 @strlen(i8* %7)
%11 = call i32 @memset(i8* %7, i32 0, i32 %10)
%12 = call i32 @strlen(i8* %1)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %3, %19
%15 = phi i64 [ %20, %19 ], [ 0, %3 ]
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 44
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = add nuw nsw i64 %15, 1
%21 = call i32 @strlen(i8* %1)
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %14, label %24
24: ; preds = %14, %19
%25 = phi i64 [ %20, %19 ], [ %15, %14 ]
%26 = trunc i64 %25 to i32
br label %27
27: ; preds = %24, %3
%28 = phi i32 [ 0, %3 ], [ %26, %24 ]
%29 = call i32 @strncpy(i8* %6, i8* %1, i32 %28)
%30 = zext i32 %28 to i64
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %30
store i8 0, i8* %31
%32 = add nuw nsw i32 %28, 1
%33 = call i32 @strlen(i8* %1)
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %50
35: ; preds = %27
%36 = add nuw nsw i64 %30, 1
br label %37
37: ; preds = %35, %42
%38 = phi i64 [ %36, %35 ], [ %43, %42 ]
%39 = getelementptr inbounds i8, i8* %1, i64 %38
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 44
br i1 %41, label %47, label %42
42: ; preds = %37
%43 = add nuw nsw i64 %38, 1
%44 = trunc i64 %43 to i32
%45 = call i32 @strlen(i8* %1)
%46 = icmp sgt i32 %45, %44
br i1 %46, label %37, label %47
47: ; preds = %42, %37
%48 = phi i64 [ %38, %37 ], [ %43, %42 ]
%49 = trunc i64 %48 to i32
br label %50
50: ; preds = %47, %27
%51 = phi i32 [ %32, %27 ], [ %49, %47 ]
%52 = zext i32 %32 to i64
%53 = getelementptr inbounds i8, i8* %1, i64 %52
%54 = sub nsw i32 %51, %32
%55 = call i32 @strncpy(i8* %7, i8* %53, i32 %54)
%56 = add nuw nsw i32 %51, 1
%57 = zext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %1, i64 %57
%59 = call i32 @strlen(i8* %1)
%60 = sub nsw i32 %59, %56
%61 = call i32 @strncpy(i8* %2, i8* %58, i32 %60)
%62 = call i32 @strlen(i8* %1)
%63 = sub nsw i32 %62, %56
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %2, i64 %64
store i8 0, i8* %65
%66 = call i32 @inet_addr(i8* %6)
ret void
}