#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_in6 {
  int sin6_port;
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int sa_family;
};
typedef int socklen_t;

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ __pib_report_err(char *, int, char *);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ inet_ntop(int const, int /*<<< orphan*/ *, char *, size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ snprintf(char *, size_t, char *, int);
size_t strlen(char *);
void parse_sockaddr(struct sockaddr *sockaddr, char *buffer, size_t size,
                    socklen_t *socklen_p) {
  size_t str_len = 0;
  socklen_t socklen = 0;
  memset(buffer, 0, size);
  switch (sockaddr->sa_family) {
  case AF_INET: {
    struct sockaddr_in *sockaddr_in = (struct sockaddr_in *)sockaddr;
    inet_ntop(AF_INET, &sockaddr_in->sin_addr, buffer, size);
    str_len = strlen(buffer);
    assert(str_len < size);
    snprintf(buffer + str_len, size - str_len, ":%u", sockaddr_in->sin_port);
    socklen = sizeof(struct sockaddr_in);
    break;
  }
  case AF_INET6: {
    struct sockaddr_in6 *sockaddr_in6 = (struct sockaddr_in6 *)sockaddr;
    inet_ntop(AF_INET6, &sockaddr_in6->sin6_addr, buffer, size);
    str_len = strlen(buffer);
    assert(str_len < size);
    snprintf(buffer + str_len, size - str_len, ":%u", sockaddr_in6->sin6_port);
    socklen = sizeof(struct sockaddr_in6);
    break;
  }
  default:
    do {
      __pib_report_err("/scratch/repos/new/home/jordi_armengol_estape/"
                       "c-scraper/outputs/2022-01-22/02-19-57/repos/nminoru/"
                       "pib/refs/heads/master/pibnetd/main.c",
                       1116, "pibnetd: sockaddr");
    } while (0);
    exit(EXIT_FAILURE);
    break;
  }
  if (socklen_p)
    *socklen_p = socklen;
}


x86 assembly (clang, -O0):
<parse_sockaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
sub    $0x80,%eax
je     1244 <parse_sockaddr+0xd4>
jmp    11bf <parse_sockaddr+0x4f>
mov    -0x44(%rbp),%eax
sub    $0x81,%eax
jne    12b6 <parse_sockaddr+0x146>
jmp    11d2 <parse_sockaddr+0x62>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
add    $0x4,%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x81,%edi
call   1030 <inet_ntop@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x10(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
lea    0xdcd(%rip),%rdx
call   1050 <snprintf@plt>
movl   $0x8,-0x2c(%rbp)
jmp    12e1 <parse_sockaddr+0x171>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
add    $0x4,%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x80,%edi
call   1030 <inet_ntop@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x10(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    -0x28(%rbp),%rsi
mov    -0x40(%rbp),%rax
mov    (%rax),%ecx
lea    0xd5b(%rip),%rdx
call   1050 <snprintf@plt>
movl   $0x8,-0x2c(%rbp)
jmp    12e1 <parse_sockaddr+0x171>
jmp    12bb <parse_sockaddr+0x14b>
lea    0xd42(%rip),%rdi
mov    $0x45c,%esi
lea    0xdbd(%rip),%rdx
call   1080 <__pib_report_err@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
je     12f5 <parse_sockaddr+0x185>
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_sockaddr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rsi,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    (%r12),%edi
cmp    $0x81,%edi
je     11a8 <parse_sockaddr+0x38>
cmp    $0x80,%edi
jne    1200 <parse_sockaddr+0x90>
mov    $0x80,%edi
lea    0x4(%r12),%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1030 <inet_ntop@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
xor    %edi,%edi
sub    %rax,%r15
seta   %dil
call   1070 <assert@plt>
add    %r13,%rbx
mov    (%r12),%ecx
lea    0xe21(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <snprintf@plt>
test   %r14,%r14
je     11f6 <parse_sockaddr+0x86>
movl   $0x8,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xdfd(%rip),%rdi
lea    0xe7d(%rip),%rdx
mov    $0x45c,%esi
call   1080 <__pib_report_err@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr_in6 = type { i32, i32 }
@.str = [4 x i8] c":%u\00"
@.str.1 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/nminoru/pib/refs/heads/master/pibnetd/main.c\00"
@.str.2 = [18 x i8] c"pibnetd: sockaddr\00"
@EXIT_FAILURE = global i32 0
define void @parse_sockaddr(%struct.sockaddr* %0, i8* %1, i64 %2, i32* %3) {
%5 = alloca %struct.sockaddr*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i32
%11 = alloca %struct.sockaddr_in*
%12 = alloca %struct.sockaddr_in6*
store %struct.sockaddr* %0, %struct.sockaddr** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32* %3, i32** %8
store i64 0, i64* %9
store i32 0, i32* %10
%13 = load i8*, i8** %6
%14 = load i64, i64* %7
%15 = call i32 @memset(i8* %13, i32 0, i64 %14)
%16 = load %struct.sockaddr*, %struct.sockaddr** %5
%17 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %16, i32 0, i32 0
%18 = load i32, i32* %17
switch i32 %18, label %69 [
i32 129, label %19
i32 128, label %44
]
19: ; preds = %4
%20 = load %struct.sockaddr*, %struct.sockaddr** %5
%21 = bitcast %struct.sockaddr* %20 to %struct.sockaddr_in*
store %struct.sockaddr_in* %21, %struct.sockaddr_in** %11
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 1
%24 = load i8*, i8** %6
%25 = load i64, i64* %7
%26 = call i32 @inet_ntop(i32 129, i32* %23, i8* %24, i64 %25)
%27 = load i8*, i8** %6
%28 = call i64 @strlen(i8* %27)
store i64 %28, i64* %9
%29 = load i64, i64* %9
%30 = load i64, i64* %7
%31 = icmp ult i64 %29, %30
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i8*, i8** %6
%35 = load i64, i64* %9
%36 = getelementptr inbounds i8, i8* %34, i64 %35
%37 = load i64, i64* %7
%38 = load i64, i64* %9
%39 = sub i64 %37, %38
%40 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i32 @snprintf(i8* %36, i64 %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %42)
store i32 8, i32* %10
br label %75
44: ; preds = %4
%45 = load %struct.sockaddr*, %struct.sockaddr** %5
%46 = bitcast %struct.sockaddr* %45 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %46, %struct.sockaddr_in6** %12
%47 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %12
%48 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %47, i32 0, i32 1
%49 = load i8*, i8** %6
%50 = load i64, i64* %7
%51 = call i32 @inet_ntop(i32 128, i32* %48, i8* %49, i64 %50)
%52 = load i8*, i8** %6
%53 = call i64 @strlen(i8* %52)
store i64 %53, i64* %9
%54 = load i64, i64* %9
%55 = load i64, i64* %7
%56 = icmp ult i64 %54, %55
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
%59 = load i8*, i8** %6
%60 = load i64, i64* %9
%61 = getelementptr inbounds i8, i8* %59, i64 %60
%62 = load i64, i64* %7
%63 = load i64, i64* %9
%64 = sub i64 %62, %63
%65 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %12
%66 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %65, i32 0, i32 0
%67 = load i32, i32* %66
%68 = call i32 @snprintf(i8* %61, i64 %64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %67)
store i32 8, i32* %10
br label %75
69: ; preds = %4
br label %70
70: ; preds = %69
%71 = call i32 @__pib_report_err(i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.1, i64 0, i64 0), i32 1116, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %72
72: ; preds = %70
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %44, %19
%76 = load i32*, i32** %8
%77 = icmp ne i32* %76, null
br i1 %77, label %78, label %81
78: ; preds = %75
%79 = load i32, i32* %10
%80 = load i32*, i32** %8
store i32 %79, i32* %80
br label %81
81: ; preds = %78, %75
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [4 x i8] c":%u\00"
@.str.1 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/nminoru/pib/refs/heads/master/pibnetd/main.c\00"
@.str.2 = [18 x i8] c"pibnetd: sockaddr\00"
@EXIT_FAILURE = global i32 0
define void @parse_sockaddr(%struct.sockaddr* %0, i8* %1, i64 %2, i32* writeonly %3) {
%5 = tail call i32 @memset(i8* %1, i32 0, i64 %2)
%6 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%7 = load i32, i32* %6
switch i32 %7, label %9 [
i32 129, label %13
i32 128, label %8
]
8: ; preds = %4
br label %13
9: ; preds = %4
%10 = tail call i32 @__pib_report_err(i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.1, i64 0, i64 0), i32 1116, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %4, %8
%14 = phi i32 [ 128, %8 ], [ %7, %4 ]
%15 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 1, i32 0
%16 = tail call i32 @inet_ntop(i32 %14, i32* %15, i8* %1, i64 %2)
%17 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%18 = icmp ult i64 %17, %2
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = getelementptr inbounds i8, i8* %1, i64 %17
%22 = sub i64 %2, %17
%23 = load i32, i32* %6
%24 = tail call i32 @snprintf(i8* %21, i64 %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = icmp eq i32* %3, null
br i1 %25, label %27, label %26
26: ; preds = %13
store i32 8, i32* %3
br label %27
27: ; preds = %26, %13
ret void
}