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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt(int, char *const *, char *);
void *htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ optarg;
int sscanf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ stderr;
int args_ip(int argc, char *const argv[], struct sockaddr_in *seraddr) {
  char ip[16], port[8];
  int ch, n;
  while ((ch = getopt(argc, argv, "s:")) != -1) {
    switch (ch) {
    case 's':
      if ((n = sscanf(optarg, "%15[0-9.]:%5[0-9]", ip, port)) < 1) {
        fprintf(stderr, "ip error\n");
        break;
      }
      seraddr->sin_family = AF_INET;
      inet_pton(AF_INET, ip, &seraddr->sin_addr);
      if (n == 2)
        seraddr->sin_port = htons(atoi(port));
      else
        seraddr->sin_port = htons(9003);
      return 0;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<args_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe7f(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
je     125e <args_ip+0xfe>
mov    -0x3c(%rbp),%eax
sub    $0x73,%eax
jne    1259 <args_ip+0xf9>
jmp    11a3 <args_ip+0x43>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    0xe48(%rip),%rsi
call   1060 <sscanf@plt>
mov    %eax,-0x40(%rbp)
cmp    $0x1,%eax
jge    11e6 <args_ip+0x86>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1259 <args_ip+0xf9>
mov    0x2df3(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x8,%rdx
call   1050 <inet_pton@plt>
cmpl   $0x2,-0x40(%rbp)
jne    1239 <args_ip+0xd9>
lea    -0x38(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    124d <args_ip+0xed>
mov    $0x232b,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1265 <args_ip+0x105>
jmp    1173 <args_ip+0x13>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<args_ip>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,(%rsp)
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe82(%rip),%r15
lea    0x8(%rsp),%r14
lea    0xe8b(%rip),%r12
jmp    1199 <args_ip+0x39>
nopl   0x0(%rax)
cmp    $0xffffffff,%eax
je     1221 <args_ip+0xc1>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1070 <getopt@plt>
cmp    $0x73,%eax
jne    1190 <args_ip+0x30>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rcx
call   1060 <sscanf@plt>
test   %eax,%eax
jg     11df <args_ip+0x7f>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
call   1040 <fprintf@plt>
jmp    1199 <args_ip+0x39>
mov    %eax,%r13d
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    (%rsp),%rbx
mov    %edi,0xc(%rbx)
lea    0x8(%rbx),%rdx
lea    0x10(%rsp),%rsi
call   1050 <inet_pton@plt>
mov    $0x232b,%edi
cmp    $0x2,%r13d
jne    1217 <args_ip+0xb7>
lea    0x8(%rsp),%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %rax,(%rbx)
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, i32, i32 }
@.str = [3 x i8] c"s:\00"
@optarg = global i32 0
@.str.1 = [18 x i8] c"%15[0-9.]:%5[0-9]\00"
@stderr = global i32 0
@.str.2 = [10 x i8] c"ip error\0A\00"
@AF_INET = global i32 0
define i32 @args_ip(i32 %0, i8** %1, %struct.sockaddr_in* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca %struct.sockaddr_in*
%8 = alloca [16 x i8]
%9 = alloca [8 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store %struct.sockaddr_in* %2, %struct.sockaddr_in** %7
br label %12
12: ; preds = %50, %3
%13 = load i32, i32* %5
%14 = load i8**, i8*** %6
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %10
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %51
17: ; preds = %12
%18 = load i32, i32* %10
switch i32 %18, label %50 [
i32 115, label %19
]
19: ; preds = %17
%20 = load i32, i32* @optarg
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%23 = call i32 @sscanf(i32 %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %22)
store i32 %23, i32* %11
%24 = icmp slt i32 %23, 1
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %50
28: ; preds = %19
%29 = load i32, i32* @AF_INET
%30 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %30, i32 0, i32 2
store i32 %29, i32* %31
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%34 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %34, i32 0, i32 1
%36 = call i32 @inet_pton(i32 %32, i8* %33, i32* %35)
%37 = load i32, i32* %11
%38 = icmp eq i32 %37, 2
br i1 %38, label %39, label %45
39: ; preds = %28
%40 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%41 = call i32 @atoi(i8* %40)
%42 = call i8* @htons(i32 %41)
%43 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %43, i32 0, i32 0
store i8* %42, i8** %44
br label %49
45: ; preds = %28
%46 = call i8* @htons(i32 9003)
%47 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %47, i32 0, i32 0
store i8* %46, i8** %48
br label %49
49: ; preds = %45, %39
store i32 0, i32* %4
br label %52
50: ; preds = %17, %25
br label %12
51: ; preds = %12
store i32 -1, i32* %4
br label %52
52: ; preds = %51, %49
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, i32, i32 }
@.str = [3 x i8] c"s:\00"
@optarg = global i32 0
@.str.1 = [18 x i8] c"%15[0-9.]:%5[0-9]\00"
@stderr = global i32 0
@.str.2 = [10 x i8] c"ip error\0A\00"
@AF_INET = global i32 0
define i32 @args_ip(i32 %0, i8** %1, %struct.sockaddr_in* %2) {
%4 = alloca [16 x i8]
%5 = alloca [8 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
br label %8
8: ; preds = %10, %3
%9 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %9, label %10 [
i32 -1, label %30
i32 115, label %11
]
10: ; preds = %8, %15
br label %8
11: ; preds = %8
%12 = load i32, i32* @optarg
%13 = call i32 @sscanf(i32 %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %7)
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %10
18: ; preds = %11
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
%22 = call i32 @inet_pton(i32 %19, i8* %6, i32* %21)
%23 = icmp eq i32 %13, 2
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @atoi(i8* %7)
br label %26
26: ; preds = %18, %24
%27 = phi i32 [ %25, %24 ], [ 9003, %18 ]
%28 = call i8* @htons(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i8* %28, i8** %29
br label %30
30: ; preds = %8, %26
%31 = phi i32 [ 0, %26 ], [ %9, %8 ]
ret i32 %31
}