#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_port;
  TYPE_1__ sin_addr;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int sscanf(char *, char *, int *, int *, int *, int *, int *, int *);
int getaddr(char *str, struct sockaddr_in *addr) {
  int a0, a1, a2, a3, p0, p1;
  if (sscanf(str, "%d,%d,%d,%d,%d,%d", &a0, &a1, &a2, &a3, &p0, &p1) != 6) {
    printf("address format error!\n");
    return -1;
  }
  char *a = (char *)&(addr->sin_addr).s_addr;
  a[0] = a0 & 0xff;
  a[1] = a1 & 0xff;
  a[2] = a2 & 0xff;
  a[3] = a3 & 0xff;
  char *p = (char *)&(addr->sin_port);
  p[0] = p0 & 0xff;
  p[1] = p1 & 0xff;
  return 0;
}


x86 assembly (clang, -O0):
<getaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec5(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r8
lea    -0x28(%rbp),%r9
lea    -0x2c(%rbp),%r10
lea    -0x30(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <sscanf@plt>
cmp    $0x6,%eax
je     1182 <getaddr+0x62>
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1201 <getaddr+0xe1>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x24(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x28(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x40(%rbp),%rax
mov    %cl,(%rax)
mov    -0x30(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x40(%rbp),%rax
mov    %cl,0x1(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getaddr>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rax
lea    0xc(%rsp),%r10
lea    0xec7(%rip),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x14(%rsp),%r8
lea    0x10(%rsp),%r9
push   %rax
push   %r10
call   1040 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
jne    118b <getaddr+0x6b>
mov    0x1c(%rsp),%al
mov    %al,0x4(%rbx)
mov    0x18(%rsp),%al
mov    %al,0x5(%rbx)
mov    0x14(%rsp),%al
mov    %al,0x6(%rbx)
mov    0x10(%rsp),%al
mov    %al,0x7(%rbx)
mov    0xc(%rsp),%al
mov    %al,(%rbx)
mov    0x8(%rsp),%al
mov    %al,0x1(%rbx)
xor    %eax,%eax
jmp    119c <getaddr+0x7c>
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [18 x i8] c"%d,%d,%d,%d,%d,%d\00"
@.str.1 = [23 x i8] c"address format error!\0A\00"
define i32 @getaddr(i8* %0, %struct.sockaddr_in* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.sockaddr_in*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %4
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %5
%14 = load i8*, i8** %4
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %11)
%16 = icmp ne i32 %15, 6
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %57
19: ; preds = %2
%20 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
%23 = bitcast i32* %22 to i8*
store i8* %23, i8** %12
%24 = load i32, i32* %6
%25 = and i32 %24, 255
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %12
%28 = getelementptr inbounds i8, i8* %27, i64 0
store i8 %26, i8* %28
%29 = load i32, i32* %7
%30 = and i32 %29, 255
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %12
%33 = getelementptr inbounds i8, i8* %32, i64 1
store i8 %31, i8* %33
%34 = load i32, i32* %8
%35 = and i32 %34, 255
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %12
%38 = getelementptr inbounds i8, i8* %37, i64 2
store i8 %36, i8* %38
%39 = load i32, i32* %9
%40 = and i32 %39, 255
%41 = trunc i32 %40 to i8
%42 = load i8*, i8** %12
%43 = getelementptr inbounds i8, i8* %42, i64 3
store i8 %41, i8* %43
%44 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %44, i32 0, i32 0
%46 = bitcast i32* %45 to i8*
store i8* %46, i8** %13
%47 = load i32, i32* %10
%48 = and i32 %47, 255
%49 = trunc i32 %48 to i8
%50 = load i8*, i8** %13
%51 = getelementptr inbounds i8, i8* %50, i64 0
store i8 %49, i8* %51
%52 = load i32, i32* %11
%53 = and i32 %52, 255
%54 = trunc i32 %53 to i8
%55 = load i8*, i8** %13
%56 = getelementptr inbounds i8, i8* %55, i64 1
store i8 %54, i8* %56
store i32 0, i32* %3
br label %57
57: ; preds = %19, %17
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [18 x i8] c"%d,%d,%d,%d,%d,%d\00"
@str = [22 x i8] c"address format error!\00"
define i32 @getaddr(i8* nocapture %0, %struct.sockaddr_in* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = bitcast i32* %8 to i8*
%15 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4, i32* %5, i32* %6, i32* %7, i32* %8)
%16 = icmp eq i32 %15, 6
br i1 %16, label %19, label %17
17: ; preds = %2
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %39
19: ; preds = %2
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
%21 = bitcast i32* %20 to i8*
%22 = load i32, i32* %3
%23 = trunc i32 %22 to i8
store i8 %23, i8* %21
%24 = load i32, i32* %4
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds i8, i8* %21, i64 1
store i8 %25, i8* %26
%27 = load i32, i32* %5
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds i8, i8* %21, i64 2
store i8 %28, i8* %29
%30 = load i32, i32* %6
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds i8, i8* %21, i64 3
store i8 %31, i8* %32
%33 = bitcast %struct.sockaddr_in* %1 to i8*
%34 = load i32, i32* %7
%35 = trunc i32 %34 to i8
store i8 %35, i8* %33
%36 = load i32, i32* %8
%37 = trunc i32 %36 to i8
%38 = getelementptr inbounds i8, i8* %33, i64 1
store i8 %37, i8* %38
br label %39
39: ; preds = %19, %17
%40 = phi i32 [ -1, %17 ], [ 0, %19 ]
ret i32 %40
}