#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
void Servaddr(struct sockaddr_in *servaddr, char *ip, char *port) {
  bzero(servaddr, sizeof(*servaddr));
  servaddr->sin_family = AF_INET;
  servaddr->sin_port = htons(atoi(port));
  if (inet_pton(AF_INET, ip, &servaddr->sin_addr) <= 0) {
    perror("inet_pton error");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<Servaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0xc,%esi
call   1060 <bzero@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1040 <inet_pton@plt>
cmp    $0x0,%rax
jg     11e1 <Servaddr+0x81>
lea    0xe2e(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Servaddr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0xc,%esi
call   1060 <bzero@plt>
mov    0x2e66(%rip),%r12
mov    (%r12),%eax
mov    %eax,0x8(%rbx)
mov    %r15,%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rbx)
mov    (%r12),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <inet_pton@plt>
test   %rax,%rax
jle    11bb <Servaddr+0x5b>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe3e(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
@.str = [16 x i8] c"inet_pton error\00"
define void @Servaddr(%struct.sockaddr_in* %0, i8* %1, i8* %2) {
%4 = alloca %struct.sockaddr_in*
%5 = alloca i8*
%6 = alloca i8*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%7 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%8 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%9 = load i32, i32* @AF_INET
%10 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %9, i32* %11
%12 = load i8*, i8** %6
%13 = call i32 @atoi(i8* %12)
%14 = call i32 @htons(i32 %13)
%15 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 1
store i32 %14, i32* %16
%17 = load i32, i32* @AF_INET
%18 = load i8*, i8** %5
%19 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 0
%21 = call i64 @inet_pton(i32 %17, i8* %18, i32* %20)
%22 = icmp sle i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %3
%24 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %3
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
@.str = [16 x i8] c"inet_pton error\00"
define void @Servaddr(%struct.sockaddr_in* %0, i8* %1, i8* nocapture %2) {
%4 = tail call i32 @bzero(%struct.sockaddr_in* %0, i32 12)
%5 = load i32, i32* @AF_INET
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 2
store i32 %5, i32* %6
%7 = tail call i32 @atoi(i8* %2)
%8 = tail call i32 @htons(i32 %7)
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1
store i32 %8, i32* %9
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
%12 = tail call i64 @inet_pton(i32 %10, i8* %1, i32* %11)
%13 = icmp slt i64 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %3
ret void
}