#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(int);
scalar_t__ inet_aton(char const *, struct in_addr *);
int /*<<< orphan*/ stderr;
int setNumAttrWithIP(const char *strIP, int iAttrID, int iValue) {
  char buf[12];
  char *p = NULL;
  long iIP = -1;
  struct in_addr inaddr;
  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(iValue); };
  p += 4;
  return adv_attr_set(12345678, sizeof(buf), buf);
}


x86 assembly (clang, -O0):
<setNumAttrWithIP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0xffffffffffffffff,-0x38(%rbp)
ff
cmpq   $0x0,-0x10(%rbp)
jne    11a0 <setNumAttrWithIP+0x50>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a3 <setNumAttrWithIP+0x153>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1060 <inet_aton@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11e2 <setNumAttrWithIP+0x92>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a3 <setNumAttrWithIP+0x153>
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     121a <setNumAttrWithIP+0xca>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a3 <setNumAttrWithIP+0x153>
lea    -0x24(%rbp),%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
lea    -0x24(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    %eax,%edi
call   1030 <htonl@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <htonl@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <htonl@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
lea    -0x24(%rbp),%rdx
mov    $0xbc614e,%edi
mov    $0xc,%esi
call   1040 <adv_attr_set@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setNumAttrWithIP>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %rdi,%rdi
je     11ca <setNumAttrWithIP+0x7a>
mov    %edx,%r14d
mov    %esi,%ebx
mov    %rdi,%rbp
lea    0x10(%rsp),%rsi
call   1060 <inet_aton@plt>
test   %rax,%rax
je     11e3 <setNumAttrWithIP+0x93>
test   %ebx,%ebx
jle    11ff <setNumAttrWithIP+0xaf>
mov    0x10(%rsp),%ebp
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    %ebp,%edi
call   1030 <htonl@plt>
mov    %rax,(%rsp)
mov    %ebx,%edi
call   1030 <htonl@plt>
mov    %rax,0x4(%rsp)
mov    %r14d,%edi
call   1030 <htonl@plt>
mov    %rax,0x8(%rsp)
mov    $0xbc614e,%edi
mov    $0xc,%esi
mov    %r15,%rdx
call   1040 <adv_attr_set@plt>
jmp    121d <setNumAttrWithIP+0xcd>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1218 <setNumAttrWithIP+0xc8>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1218 <setNumAttrWithIP+0xc8>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i64 }
@stderr = global i32 0
@.str = [23 x i8] c"strIP is NULL, error!\0A\00"
@.str.1 = [16 x i8] c"invalid IP: %s\0A\00"
@.str.2 = [21 x i8] c"invalid iAttrID: %d\0A\00"
define i32 @setNumAttrWithIP(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [12 x i8]
%9 = alloca i8*
%10 = alloca i64
%11 = alloca %struct.in_addr
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* null, i8** %9
store i64 -1, i64* %10
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %59
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = call i64 @inet_aton(i8* %18, %struct.in_addr* %11)
%20 = icmp eq i64 0, %19
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %5
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %23)
store i32 -1, i32* %4
br label %59
25: ; preds = %17
%26 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %11, i32 0, i32 0
%27 = load i64, i64* %26
store i64 %27, i64* %10
%28 = load i32, i32* %6
%29 = icmp sle i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = load i32, i32* %6
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %32)
store i32 -1, i32* %4
br label %59
34: ; preds = %25
%35 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 0
%36 = call i32 @bzero(i8* %35, i32 12)
%37 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 0
store i8* %37, i8** %9
%38 = load i64, i64* %10
%39 = trunc i64 %38 to i32
%40 = call i64 @htonl(i32 %39)
%41 = load i8*, i8** %9
%42 = bitcast i8* %41 to i64*
store i64 %40, i64* %42
%43 = load i8*, i8** %9
%44 = getelementptr inbounds i8, i8* %43, i64 4
store i8* %44, i8** %9
%45 = load i32, i32* %6
%46 = call i64 @htonl(i32 %45)
%47 = load i8*, i8** %9
%48 = bitcast i8* %47 to i64*
store i64 %46, i64* %48
%49 = load i8*, i8** %9
%50 = getelementptr inbounds i8, i8* %49, i64 4
store i8* %50, i8** %9
%51 = load i32, i32* %7
%52 = call i64 @htonl(i32 %51)
%53 = load i8*, i8** %9
%54 = bitcast i8* %53 to i64*
store i64 %52, i64* %54
%55 = load i8*, i8** %9
%56 = getelementptr inbounds i8, i8* %55, i64 4
store i8* %56, i8** %9
%57 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 0
%58 = call i32 @adv_attr_set(i32 12345678, i32 12, i8* %57)
store i32 %58, i32* %4
br label %59
59: ; preds = %34, %30, %21, %14
%60 = load i32, i32* %4
ret i32 %60
}

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