#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_storage {
  int ss_family;
};
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_port;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
};
typedef int socklen_t;

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void check_sockaddr(int pf, struct sockaddr_storage *ss, socklen_t salen) {
  struct sockaddr_in6 *sin6;
  struct sockaddr_in *sin;
  socklen_t wanted_size = 0;
  switch (pf) {
  case AF_INET:
    wanted_size = sizeof(*sin);
    sin = (void *)ss;
    if (!sin->sin_port)
      fprintf(stderr, "accept: something wrong: ip connection from port 0");
    break;
  case AF_INET6:
    wanted_size = sizeof(*sin6);
    sin6 = (void *)ss;
    if (!sin6->sin6_port)
      fprintf(stderr, "accept: something wrong: ipv6 connection from port 0");
    break;
  default:
    fprintf(stderr, "accept: Unknown pf %d, salen %u\n", pf, salen);
    return;
  }
  if (salen != wanted_size)
    fprintf(stderr, "accept: size mismatch, got %d expected %d\n", (int)salen,
            wanted_size);
  if (ss->ss_family != pf)
    fprintf(stderr, "accept: pf mismatch, expect %d, ss_family is %d\n",
            (int)ss->ss_family, pf);
}


x86 assembly (clang, -O0):
<check_sockaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x80,%eax
je     118a <check_sockaddr+0x7a>
jmp    113f <check_sockaddr+0x2f>
mov    -0x30(%rbp),%eax
sub    $0x81,%eax
jne    11c2 <check_sockaddr+0xb2>
jmp    1152 <check_sockaddr+0x42>
movl   $0x4,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1185 <check_sockaddr+0x75>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11e4 <check_sockaddr+0xd4>
movl   $0x4,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11bd <check_sockaddr+0xad>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11e4 <check_sockaddr+0xd4>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    123c <check_sockaddr+0x12c>
mov    -0x14(%rbp),%eax
cmp    -0x2c(%rbp),%eax
je     120d <check_sockaddr+0xfd>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x2c(%rbp),%ecx
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
cmp    -0x4(%rbp),%eax
je     123c <check_sockaddr+0x12c>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    -0x4(%rbp),%ecx
lea    0xe7f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_sockaddr>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %edi,%ebx
cmp    $0x80,%edi
je     113b <check_sockaddr+0x2b>
cmp    $0x81,%ebx
jne    1189 <check_sockaddr+0x79>
cmpl   $0x0,0x0(%rbp)
jne    1158 <check_sockaddr+0x48>
lea    0xec7(%rip),%rsi
jmp    1148 <check_sockaddr+0x38>
cmpl   $0x0,0x0(%rbp)
jne    1158 <check_sockaddr+0x48>
lea    0xeeb(%rip),%rsi
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    $0x4,%r14d
je     117d <check_sockaddr+0x6d>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xf1b(%rip),%rsi
mov    %r14d,%edx
mov    $0x4,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%rbp),%edx
cmp    %ebx,%edx
jne    11a0 <check_sockaddr+0x90>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xecf(%rip),%rsi
mov    %ebx,%edx
mov    %r14d,%ecx
jmp    11b2 <check_sockaddr+0xa2>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xf04(%rip),%rsi
mov    %ebx,%ecx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fprintf@plt>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr_in = type { i32 }
@stderr = global i32 0
@.str = [51 x i8] c"accept: something wrong: ip connection from port 0\00"
@.str.1 = [53 x i8] c"accept: something wrong: ipv6 connection from port 0\00"
@.str.2 = [33 x i8] c"accept: Unknown pf %d, salen %u\0A\00"
@.str.3 = [43 x i8] c"accept: size mismatch, got %d expected %d\0A\00"
@.str.4 = [49 x i8] c"accept: pf mismatch, expect %d, ss_family is %d\0A\00"
define void @check_sockaddr(i32 %0, %struct.sockaddr_storage* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr_storage*
%6 = alloca i32
%7 = alloca %struct.sockaddr_in6*
%8 = alloca %struct.sockaddr_in*
%9 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr_storage* %1, %struct.sockaddr_storage** %5
store i32 %2, i32* %6
store i32 0, i32* %9
%10 = load i32, i32* %4
switch i32 %10, label %35 [
i32 129, label %11
i32 128, label %23
]
11: ; preds = %3
store i32 4, i32* %9
%12 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%13 = bitcast %struct.sockaddr_storage* %12 to i8*
%14 = bitcast i8* %13 to %struct.sockaddr_in*
store %struct.sockaddr_in* %14, %struct.sockaddr_in** %8
%15 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %11
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %19, %11
br label %40
23: ; preds = %3
store i32 4, i32* %9
%24 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%25 = bitcast %struct.sockaddr_storage* %24 to i8*
%26 = bitcast i8* %25 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %26, %struct.sockaddr_in6** %7
%27 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %7
%28 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %23
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %31, %23
br label %40
35: ; preds = %3
%36 = load i32, i32* @stderr
%37 = load i32, i32* %4
%38 = load i32, i32* %6
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %37, i32 %38)
br label %62
40: ; preds = %34, %22
%41 = load i32, i32* %6
%42 = load i32, i32* %9
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %49
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = load i32, i32* %6
%47 = load i32, i32* %9
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %46, i32 %47)
br label %49
49: ; preds = %44, %40
%50 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%51 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = load i32, i32* %4
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %62
55: ; preds = %49
%56 = load i32, i32* @stderr
%57 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%58 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %57, i32 0, i32 0
%59 = load i32, i32* %58
%60 = load i32, i32* %4
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i32 %59, i32 %60)
br label %62
62: ; preds = %35, %55, %49
ret void
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
@stderr = global i32 0
@.str = [51 x i8] c"accept: something wrong: ip connection from port 0\00"
@.str.1 = [53 x i8] c"accept: something wrong: ipv6 connection from port 0\00"
@.str.2 = [33 x i8] c"accept: Unknown pf %d, salen %u\0A\00"
@.str.3 = [43 x i8] c"accept: size mismatch, got %d expected %d\0A\00"
@.str.4 = [49 x i8] c"accept: pf mismatch, expect %d, ss_family is %d\0A\00"
define void @check_sockaddr(i32 %0, %struct.sockaddr_storage* nocapture %1, i32 %2) {
switch i32 %0, label %12 [
i32 129, label %4
i32 128, label %8
]
4: ; preds = %3
%5 = getelementptr %struct.sockaddr_storage, %struct.sockaddr_storage* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, 0
br i1 %7, label %15, label %19
8: ; preds = %3
%9 = getelementptr %struct.sockaddr_storage, %struct.sockaddr_storage* %1, i64 0, i32 0
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %19
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %2)
br label %31
15: ; preds = %8, %4
%16 = phi i8* [ getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), %8 ]
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* %16)
br label %19
19: ; preds = %15, %8, %4
%20 = icmp eq i32 %2, 4
br i1 %20, label %24, label %21
21: ; preds = %19
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %2, i32 4)
br label %24
24: ; preds = %21, %19
%25 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %1, i64 0, i32 0
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, %0
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i32 %26, i32 %0)
br label %31
31: ; preds = %24, %28, %12
ret void
}