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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
scalar_t__ inet_pton(int /*<<< orphan*/, char *, TYPE_1__ *);
int /*<<< orphan*/ strcmp(char *, char *);
int svz_inet_aton(char *str, struct sockaddr_in *addr) {
  if (!strcmp(str, "*")) {
    addr->sin_addr.s_addr = INADDR_ANY;
    return 0;
  }
  if (inet_pton(AF_INET, str, &addr->sin_addr) == 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<svz_inet_aton>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec5(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1164 <svz_inet_aton+0x44>
mov    0x2e90(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1197 <svz_inet_aton+0x77>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <inet_pton@plt>
cmp    $0x0,%rax
jne    1190 <svz_inet_aton+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <svz_inet_aton+0x77>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<svz_inet_aton>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xecf(%rip),%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1156 <svz_inet_aton+0x36>
mov    0x2ea7(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <inet_pton@plt>
cmp    $0x1,%rax
sbb    %eax,%eax
jmp    1164 <svz_inet_aton+0x44>
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [2 x i8] c"*\00"
@INADDR_ANY = global i32 0
@AF_INET = global i32 0
define i32 @svz_inet_aton(i8* %0, %struct.sockaddr_in* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.sockaddr_in*
store i8* %0, i8** %4
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %5
%6 = load i8*, i8** %4
%7 = call i32 @strcmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = load i32, i32* @INADDR_ANY
%11 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i32 0, i32 0
store i32 %10, i32* %13
store i32 0, i32* %3
br label %23
14: ; preds = %2
%15 = load i32, i32* @AF_INET
%16 = load i8*, i8** %4
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%19 = call i64 @inet_pton(i32 %15, i8* %16, %struct.TYPE_2__* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
store i32 -1, i32* %3
br label %23
22: ; preds = %14
store i32 0, i32* %3
br label %23
23: ; preds = %22, %21, %9
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [2 x i8] c"*\00"
@INADDR_ANY = global i32 0
@AF_INET = global i32 0
define i32 @svz_inet_aton(i8* %0, %struct.sockaddr_in* %1) {
%3 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @INADDR_ANY
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %6, i32* %7
br label %14
8: ; preds = %2
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%11 = tail call i64 @inet_pton(i32 %9, i8* %0, %struct.TYPE_2__* %10)
%12 = icmp eq i64 %11, 0
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %8, %5
%15 = phi i32 [ 0, %5 ], [ %13, %8 ]
ret i32 %15
}