#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 */
struct in_addr {
  long s_addr;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int adv_attr_set(int, int, char *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
unsigned long htonl(size_t);
scalar_t__ inet_aton(char const *, struct in_addr *);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int /*<<< orphan*/ stderr;
int setStrAttrWithIP(const char *strIP, int iAttrID, size_t len,
                     const char *pval) {
  char buf[65536];
  char *p = NULL;
  long iIP = -1;
  struct in_addr inaddr;
  if (len > sizeof(buf)) {
    fprintf(stderr, "len is %zd, longger than 65536!\n", len);
    return -1;
  }
  if (!strIP) {
    fprintf(stderr, "strIP is NULL, error!\n");
    return -1;
  }
  if (0 == inet_aton(strIP, &inaddr)) {
    fprintf(stderr, "invalid IP: %s\n", strIP);
    return -1;
  }
  iIP = inaddr.s_addr;
  if (iAttrID <= 0) {
    fprintf(stderr, "invalid iAttrID: %d\n", iAttrID);
    return -1;
  }
  bzero(buf, sizeof(buf));
  p = buf;
  { *((unsigned long *)(p)) = htonl(iIP); };
  p += 4;
  { *((unsigned long *)(p)) = htonl(iAttrID); };
  p += 4;
  { *((unsigned long *)(p)) = htonl(len); };
  p += 4;
  memcpy(p, pval, len);
  p += len;
  return adv_attr_set(12345679, p - buf, buf);
}


x86 assembly (clang, -O0):
<setStrAttrWithIP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10050,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x10038(%rbp)
movq   $0xffffffffffffffff,-0x10040(%rbp)
ff ff ff ff
cmpq   $0x10000,-0x20(%rbp)
jbe    11c5 <setStrAttrWithIP+0x65>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    135d <setStrAttrWithIP+0x1fd>
cmpq   $0x0,-0x10(%rbp)
jne    11f3 <setStrAttrWithIP+0x93>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    135d <setStrAttrWithIP+0x1fd>
mov    -0x10(%rbp),%rdi
lea    -0x10048(%rbp),%rsi
call   1070 <inet_aton@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1238 <setStrAttrWithIP+0xd8>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    135d <setStrAttrWithIP+0x1fd>
mov    -0x10048(%rbp),%rax
mov    %rax,-0x10040(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1276 <setStrAttrWithIP+0x116>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xde5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    135d <setStrAttrWithIP+0x1fd>
lea    -0x10030(%rbp),%rdi
mov    $0x10000,%esi
call   1080 <bzero@plt>
lea    -0x10030(%rbp),%rax
mov    %rax,-0x10038(%rbp)
mov    -0x10040(%rbp),%rdi
call   1030 <htonl@plt>
mov    %rax,%rcx
mov    -0x10038(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10038(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10038(%rbp)
movslq -0x14(%rbp),%rdi
call   1030 <htonl@plt>
mov    %rax,%rcx
mov    -0x10038(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10038(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10038(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <htonl@plt>
mov    %rax,%rcx
mov    -0x10038(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10038(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10038(%rbp)
mov    -0x10038(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    -0x10038(%rbp),%rax
mov    %rax,-0x10038(%rbp)
mov    -0x10038(%rbp),%rax
lea    -0x10030(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    -0x10030(%rbp),%rdx
mov    $0xbc614f,%edi
call   1040 <adv_attr_set@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setStrAttrWithIP>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10010,%rsp
mov    %rdx,%rbx
cmp    $0x10001,%rdx
jb     119a <setStrAttrWithIP+0x3a>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    127d <setStrAttrWithIP+0x11d>
mov    %rdi,%rbp
test   %rdi,%rdi
je     1232 <setStrAttrWithIP+0xd2>
mov    %rcx,%r14
mov    %esi,%r12d
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   1070 <inet_aton@plt>
test   %rax,%rax
je     124b <setStrAttrWithIP+0xeb>
test   %r12d,%r12d
jle    1263 <setStrAttrWithIP+0x103>
mov    0x8(%rsp),%rbp
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x10000,%esi
call   1080 <bzero@plt>
mov    %rbp,%rdi
call   1030 <htonl@plt>
mov    %rax,0x10(%rsp)
mov    %r12d,%edi
call   1030 <htonl@plt>
mov    %rax,0x14(%rsp)
mov    %rbx,%rdi
call   1030 <htonl@plt>
mov    %rax,0x18(%rsp)
lea    0x1c(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1060 <memcpy@plt>
add    %ebx,%ebp
sub    %r15d,%ebp
mov    $0xbc614f,%edi
mov    %ebp,%esi
mov    %r15,%rdx
call   1040 <adv_attr_set@plt>
jmp    1282 <setStrAttrWithIP+0x122>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    127d <setStrAttrWithIP+0x11d>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
mov    %rbp,%rdx
jmp    118e <setStrAttrWithIP+0x2e>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10010,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i64 }
@stderr = global i32 0
@.str = [33 x i8] c"len is %zd, longger than 65536!\0A\00"
@.str.1 = [23 x i8] c"strIP is NULL, error!\0A\00"
@.str.2 = [16 x i8] c"invalid IP: %s\0A\00"
@.str.3 = [21 x i8] c"invalid iAttrID: %d\0A\00"
define i32 @setStrAttrWithIP(i8* %0, i32 %1, i64 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca [65536 x i8]
%11 = alloca i8*
%12 = alloca i64
%13 = alloca %struct.in_addr
store i8* %0, i8** %6
store i32 %1, i32* %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i8* null, i8** %11
store i64 -1, i64* %12
%14 = load i64, i64* %8
%15 = icmp ugt i64 %14, 65536
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i32, i32* @stderr
%18 = load i64, i64* %8
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i64 %18)
store i32 -1, i32* %5
br label %81
20: ; preds = %4
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
br label %81
26: ; preds = %20
%27 = load i8*, i8** %6
%28 = call i64 @inet_aton(i8* %27, %struct.in_addr* %13)
%29 = icmp eq i64 0, %28
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %6
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %32)
store i32 -1, i32* %5
br label %81
34: ; preds = %26
%35 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %13, i32 0, i32 0
%36 = load i64, i64* %35
store i64 %36, i64* %12
%37 = load i32, i32* %7
%38 = icmp sle i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = load i32, i32* %7
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %41)
store i32 -1, i32* %5
br label %81
43: ; preds = %34
%44 = getelementptr inbounds [65536 x i8], [65536 x i8]* %10, i64 0, i64 0
%45 = call i32 @bzero(i8* %44, i32 65536)
%46 = getelementptr inbounds [65536 x i8], [65536 x i8]* %10, i64 0, i64 0
store i8* %46, i8** %11
%47 = load i64, i64* %12
%48 = call i64 @htonl(i64 %47)
%49 = load i8*, i8** %11
%50 = bitcast i8* %49 to i64*
store i64 %48, i64* %50
%51 = load i8*, i8** %11
%52 = getelementptr inbounds i8, i8* %51, i64 4
store i8* %52, i8** %11
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = call i64 @htonl(i64 %54)
%56 = load i8*, i8** %11
%57 = bitcast i8* %56 to i64*
store i64 %55, i64* %57
%58 = load i8*, i8** %11
%59 = getelementptr inbounds i8, i8* %58, i64 4
store i8* %59, i8** %11
%60 = load i64, i64* %8
%61 = call i64 @htonl(i64 %60)
%62 = load i8*, i8** %11
%63 = bitcast i8* %62 to i64*
store i64 %61, i64* %63
%64 = load i8*, i8** %11
%65 = getelementptr inbounds i8, i8* %64, i64 4
store i8* %65, i8** %11
%66 = load i8*, i8** %11
%67 = load i8*, i8** %9
%68 = load i64, i64* %8
%69 = call i32 @memcpy(i8* %66, i8* %67, i64 %68)
%70 = load i64, i64* %8
%71 = load i8*, i8** %11
%72 = getelementptr inbounds i8, i8* %71, i64 %70
store i8* %72, i8** %11
%73 = load i8*, i8** %11
%74 = getelementptr inbounds [65536 x i8], [65536 x i8]* %10, i64 0, i64 0
%75 = ptrtoint i8* %73 to i64
%76 = ptrtoint i8* %74 to i64
%77 = sub i64 %75, %76
%78 = trunc i64 %77 to i32
%79 = getelementptr inbounds [65536 x i8], [65536 x i8]* %10, i64 0, i64 0
%80 = call i32 @adv_attr_set(i32 12345679, i32 %78, i8* %79)
store i32 %80, i32* %5
br label %81
81: ; preds = %43, %39, %30, %23, %16
%82 = load i32, i32* %5
ret i32 %82
}

LLVM IR (-O2):
%struct.in_addr = type { i64 }
@stderr = global i32 0
@.str = [33 x i8] c"len is %zd, longger than 65536!\0A\00"
@.str.1 = [23 x i8] c"strIP is NULL, error!\0A\00"
@.str.2 = [16 x i8] c"invalid IP: %s\0A\00"
@.str.3 = [21 x i8] c"invalid iAttrID: %d\0A\00"
define i32 @setStrAttrWithIP(i8* %0, i32 %1, i64 %2, i8* %3) {
%5 = alloca [65536 x i8]
%6 = alloca %struct.in_addr
%7 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 0
%8 = bitcast %struct.in_addr* %6 to i8*
%9 = icmp ugt i64 %2, 65536
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i64 %2)
br label %50
13: ; preds = %4
%14 = icmp eq i8* %0, null
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %50
18: ; preds = %13
%19 = call i64 @inet_aton(i8* %0, %struct.in_addr* %6)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %50
24: ; preds = %18
%25 = icmp slt i32 %1, 1
br i1 %25, label %26, label %29
26: ; preds = %24
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %1)
br label %50
29: ; preds = %24
%30 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i64 0, i32 0
%31 = load i64, i64* %30
%32 = call i32 @bzero(i8* %7, i32 65536)
%33 = call i64 @htonl(i64 %31)
%34 = bitcast [65536 x i8]* %5 to i64*
store i64 %33, i64* %34
%35 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 4
%36 = zext i32 %1 to i64
%37 = call i64 @htonl(i64 %36)
%38 = bitcast i8* %35 to i64*
store i64 %37, i64* %38
%39 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 8
%40 = call i64 @htonl(i64 %2)
%41 = bitcast i8* %39 to i64*
store i64 %40, i64* %41
%42 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 12
%43 = call i32 @memcpy(i8* %42, i8* %3, i64 %2)
%44 = getelementptr inbounds i8, i8* %42, i64 %2
%45 = ptrtoint i8* %44 to i64
%46 = ptrtoint [65536 x i8]* %5 to i64
%47 = sub i64 %45, %46
%48 = trunc i64 %47 to i32
%49 = call i32 @adv_attr_set(i32 12345679, i32 %48, i8* %7)
br label %50
50: ; preds = %29, %26, %21, %15, %10
%51 = phi i32 [ -1, %10 ], [ -1, %21 ], [ -1, %26 ], [ %49, %29 ], [ -1, %15 ]
ret i32 %51
}