#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 */
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, int *, int *, int *,
                          int *);
int _analysis_ipaddr(char *str, char **re_addr, int *re_port) {
  static char addr[16];
  int ip[4];
  int port[2];
  int m;
  int i = 0;
  sscanf(str, "%d,%d,%d,%d,%d,%d", &ip[0], &ip[1], &ip[2], &ip[3], &port[0],
         &port[1]);
  while (i < 4) {
    if ((ip[i] > 255) || (ip[i] < 0)) {
      return -1;
    }
    i++;
  }
  m = port[0] * 256 + port[1];
  if (m > 65535) {
    return -1;
  }
  snprintf(addr, 16, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
  *re_port = m;
  *re_addr = addr;
  return 0;
}


x86 assembly (clang, -O0):
<_analysis_ipaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    -0x30(%rbp),%rcx
add    $0x4,%rcx
lea    -0x30(%rbp),%r8
add    $0x8,%r8
lea    -0x30(%rbp),%r9
add    $0xc,%r9
lea    -0x38(%rbp),%r10
lea    -0x38(%rbp),%rax
add    $0x4,%rax
lea    0xe92(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <sscanf@plt>
cmpl   $0x4,-0x40(%rbp)
jge    11c1 <_analysis_ipaddr+0xa1>
movslq -0x40(%rbp),%rax
cmpl   $0xff,-0x30(%rbp,%rax,4)
jg     11a7 <_analysis_ipaddr+0x87>
movslq -0x40(%rbp),%rax
cmpl   $0x0,-0x30(%rbp,%rax,4)
jge    11b3 <_analysis_ipaddr+0x93>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <_analysis_ipaddr+0x10d>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    117c <_analysis_ipaddr+0x5c>
mov    -0x38(%rbp),%eax
shl    $0x8,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0xffff,-0x3c(%rbp)
jle    11e6 <_analysis_ipaddr+0xc6>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <_analysis_ipaddr+0x10d>
mov    -0x30(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x28(%rbp),%r9d
mov    -0x24(%rbp),%eax
lea    0x2e45(%rip),%rdi
mov    $0x10,%esi
lea    0xe0b(%rip),%rdx
mov    %eax,(%rsp)
call   1030 <snprintf@plt>
mov    -0x3c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
lea    0x2e1d(%rip),%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_analysis_ipaddr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0x14(%rsp),%rax
lea    0x10(%rsp),%rbp
lea    0xeb0(%rip),%rsi
mov    %rsp,%rdx
push   %rax
push   %rbp
call   1040 <sscanf@plt>
add    $0x10,%rsp
mov    (%rsp),%ecx
mov    $0xffffffff,%eax
cmp    $0xff,%ecx
ja     11d8 <_analysis_ipaddr+0xb8>
mov    0x4(%rsp),%r8d
cmp    $0xff,%r8d
ja     11d8 <_analysis_ipaddr+0xb8>
mov    0x8(%rsp),%r9d
cmp    $0xff,%r9d
ja     11d8 <_analysis_ipaddr+0xb8>
mov    0xc(%rsp),%r10d
cmp    $0xff,%r10d
ja     11d8 <_analysis_ipaddr+0xb8>
mov    0x10(%rsp),%ebp
shl    $0x8,%ebp
add    0x14(%rsp),%ebp
cmp    $0xffff,%ebp
jg     11d8 <_analysis_ipaddr+0xb8>
sub    $0x8,%rsp
lea    0x2e8a(%rip),%r15
lea    0xe55(%rip),%rdx
mov    %r15,%rdi
mov    $0x10,%esi
push   %r10
call   1030 <snprintf@plt>
add    $0x10,%rsp
mov    %ebp,(%r14)
mov    %r15,(%rbx)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@_analysis_ipaddr.addr = internal global [16 x i8] zeroinitializer
@.str = [18 x i8] c"%d,%d,%d,%d,%d,%d\00"
@.str.1 = [12 x i8] c"%d.%d.%d.%d\00"
define i32 @_analysis_ipaddr(i8* %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca [4 x i32]
%9 = alloca [2 x i32]
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32* %2, i32** %7
store i32 0, i32* %11
%12 = load i8*, i8** %5
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 1
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 2
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 3
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%19 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32* %13, i32* %14, i32* %15, i32* %16, i32* %17, i32* %18)
br label %20
20: ; preds = %36, %3
%21 = load i32, i32* %11
%22 = icmp slt i32 %21, 4
br i1 %22, label %23, label %39
23: ; preds = %20
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = icmp sgt i32 %27, 255
br i1 %28, label %35, label %29
29: ; preds = %23
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29, %23
store i32 -1, i32* %4
br label %62
36: ; preds = %29
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 1
store i32 %38, i32* %11
br label %20
39: ; preds = %20
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%41 = load i32, i32* %40
%42 = mul nsw i32 %41, 256
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%44 = load i32, i32* %43
%45 = add nsw i32 %42, %44
store i32 %45, i32* %10
%46 = load i32, i32* %10
%47 = icmp sgt i32 %46, 65535
br i1 %47, label %48, label %49
48: ; preds = %39
store i32 -1, i32* %4
br label %62
49: ; preds = %39
%50 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%51 = load i32, i32* %50
%52 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 1
%53 = load i32, i32* %52
%54 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 2
%55 = load i32, i32* %54
%56 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 3
%57 = load i32, i32* %56
%58 = call i32 @snprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @_analysis_ipaddr.addr, i64 0, i64 0), i32 16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %51, i32 %53, i32 %55, i32 %57)
%59 = load i32, i32* %10
%60 = load i32*, i32** %7
store i32 %59, i32* %60
%61 = load i8**, i8*** %6
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @_analysis_ipaddr.addr, i64 0, i64 0), i8** %61
store i32 0, i32* %4
br label %62
62: ; preds = %49, %48, %35
%63 = load i32, i32* %4
ret i32 %63
}

LLVM IR (-O2):
@_analysis_ipaddr.addr = internal global [16 x i8] zeroinitializer
@.str = [18 x i8] c"%d,%d,%d,%d,%d,%d\00"
@.str.1 = [12 x i8] c"%d.%d.%d.%d\00"
define i32 @_analysis_ipaddr(i8* nocapture %0, i8** nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca [4 x i32]
%5 = alloca [2 x i32]
%6 = bitcast [4 x i32]* %4 to i8*
%7 = bitcast [2 x i32]* %5 to i8*
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%14 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %9, i32* %10, i32* %11, i32* %12, i32* %13)
%15 = load i32, i32* %8
%16 = icmp ugt i32 %15, 255
br i1 %16, label %34, label %17
17: ; preds = %3
%18 = load i32, i32* %9
%19 = icmp ugt i32 %18, 255
br i1 %19, label %34, label %20
20: ; preds = %17
%21 = load i32, i32* %10
%22 = icmp ugt i32 %21, 255
br i1 %22, label %34, label %23
23: ; preds = %20
%24 = load i32, i32* %11
%25 = icmp ugt i32 %24, 255
br i1 %25, label %34, label %26
26: ; preds = %23
%27 = load i32, i32* %12
%28 = shl nsw i32 %27, 8
%29 = load i32, i32* %13
%30 = add nsw i32 %28, %29
%31 = icmp sgt i32 %30, 65535
br i1 %31, label %34, label %32
32: ; preds = %26
%33 = call i32 @snprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @_analysis_ipaddr.addr, i64 0, i64 0), i32 16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %18, i32 %21, i32 %24)
store i32 %30, i32* %2
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @_analysis_ipaddr.addr, i64 0, i64 0), i8** %1
br label %34
34: ; preds = %3, %17, %20, %23, %26, %32
%35 = phi i32 [ 0, %32 ], [ -1, %26 ], [ -1, %23 ], [ -1, %20 ], [ -1, %17 ], [ -1, %3 ]
ret i32 %35
}