#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 */
typedef int /*<<< orphan*/ netlen;
typedef int /*<<< orphan*/ netNConnNames;
typedef int /*<<< orphan*/ hdr;

/* Variables and functions */
unsigned short htons(unsigned short);
int strlen(char const *);
int /*<<< orphan*/ write(int, ...);
void write_connnames(int sockfd, char cmd, const char **connNames,
                     int nConnNames) {
  unsigned short len, netlen;
  int ii;
  for (len = 0, ii = 0; ii < nConnNames; ++ii) {
    len += 1 + strlen(connNames[ii]);
  }
  unsigned char hdr[] = {0, cmd};
  unsigned short netNConnNames = htons(nConnNames);
  netlen = sizeof(hdr) + sizeof(netNConnNames) + len;
  netlen = htons(netlen);
  write(sockfd, &netlen, sizeof(netlen));
  write(sockfd, &hdr, sizeof(hdr));
  write(sockfd, &netNConnNames, sizeof(netNConnNames));
  for (len = 0, ii = 0; ii < nConnNames; ++ii) {
    write(sockfd, connNames[ii], strlen(connNames[ii]));
    write(sockfd, "\n", 1);
  }
}


x86 assembly (clang, -O0):
<write_connnames>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movw   $0x0,-0x16(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118f <write_connnames+0x5f>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
add    $0x1,%ecx
movzwl -0x16(%rbp),%eax
add    %ecx,%eax
mov    %ax,-0x16(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <write_connnames+0x25>
movb   $0x0,-0x1e(%rbp)
mov    -0x5(%rbp),%al
mov    %al,-0x1d(%rbp)
mov    -0x14(%rbp),%eax
movzwl %ax,%edi
call   1050 <htons@plt>
mov    %ax,-0x20(%rbp)
movzwl -0x16(%rbp),%eax
add    $0x4,%rax
mov    %ax,-0x18(%rbp)
movzwl -0x18(%rbp),%edi
call   1050 <htons@plt>
mov    %ax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x1e(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <write@plt>
movw   $0x0,-0x16(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    126e <write_connnames+0x13e>
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
lea    0xdac(%rip),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1207 <write_connnames+0xd7>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_connnames>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r14d
mov    %rdx,%r12
mov    %edi,%r15d
mov    %ecx,%r13d
test   %ecx,%ecx
jle    1180 <write_connnames+0x50>
mov    %esi,0x14(%rsp)
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    (%r12,%rbp,8),%rdi
call   1040 <strlen@plt>
add    %eax,%ebx
add    $0x1,%ebx
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1160 <write_connnames+0x30>
add    $0x4,%ebx
mov    0x14(%rsp),%esi
jmp    1184 <write_connnames+0x54>
mov    $0x4,%bx
movb   $0x0,0xe(%rsp)
mov    %sil,0xf(%rsp)
movzwl %r14w,%edi
call   1050 <htons@plt>
mov    %ax,0x10(%rsp)
movzwl %bx,%edi
call   1050 <htons@plt>
mov    %ax,0x12(%rsp)
lea    0x12(%rsp),%rsi
mov    $0x2,%edx
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <write@plt>
lea    0xe(%rsp),%rsi
mov    $0x2,%edx
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <write@plt>
lea    0x10(%rsp),%rsi
mov    $0x2,%edx
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <write@plt>
test   %r14d,%r14d
jle    1236 <write_connnames+0x106>
lea    0xe0f(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12,%rbp,8),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1200 <write_connnames+0xd0>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define void @write_connnames(i32 %0, i8 signext %1, i8** %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i16
%10 = alloca i16
%11 = alloca i32
%12 = alloca [2 x i8]
%13 = alloca i16
store i32 %0, i32* %5
store i8 %1, i8* %6
store i8** %2, i8*** %7
store i32 %3, i32* %8
store i16 0, i16* %9
store i32 0, i32* %11
br label %14
14: ; preds = %30, %4
%15 = load i32, i32* %11
%16 = load i32, i32* %8
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %33
18: ; preds = %14
%19 = load i8**, i8*** %7
%20 = load i32, i32* %11
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 1, %24
%26 = load i16, i16* %9
%27 = zext i16 %26 to i32
%28 = add nsw i32 %27, %25
%29 = trunc i32 %28 to i16
store i16 %29, i16* %9
br label %30
30: ; preds = %18
%31 = load i32, i32* %11
%32 = add nsw i32 %31, 1
store i32 %32, i32* %11
br label %14
33: ; preds = %14
%34 = getelementptr inbounds [2 x i8], [2 x i8]* %12, i64 0, i64 0
store i8 0, i8* %34
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8, i8* %6
store i8 %36, i8* %35
%37 = load i32, i32* %8
%38 = trunc i32 %37 to i16
%39 = call zeroext i16 @htons(i16 zeroext %38)
store i16 %39, i16* %13
%40 = load i16, i16* %9
%41 = zext i16 %40 to i64
%42 = add i64 4, %41
%43 = trunc i64 %42 to i16
store i16 %43, i16* %10
%44 = load i16, i16* %10
%45 = call zeroext i16 @htons(i16 zeroext %44)
store i16 %45, i16* %10
%46 = load i32, i32* %5
%47 = call i32 (i32, ...) @write(i32 %46, i16* %10, i64 2)
%48 = load i32, i32* %5
%49 = call i32 (i32, ...) @write(i32 %48, [2 x i8]* %12, i64 2)
%50 = load i32, i32* %5
%51 = call i32 (i32, ...) @write(i32 %50, i16* %13, i64 2)
store i16 0, i16* %9
store i32 0, i32* %11
br label %52
52: ; preds = %72, %33
%53 = load i32, i32* %11
%54 = load i32, i32* %8
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %75
56: ; preds = %52
%57 = load i32, i32* %5
%58 = load i8**, i8*** %7
%59 = load i32, i32* %11
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %58, i64 %60
%62 = load i8*, i8** %61
%63 = load i8**, i8*** %7
%64 = load i32, i32* %11
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8*, i8** %63, i64 %65
%67 = load i8*, i8** %66
%68 = call i32 @strlen(i8* %67)
%69 = call i32 (i32, ...) @write(i32 %57, i8* %62, i32 %68)
%70 = load i32, i32* %5
%71 = call i32 (i32, ...) @write(i32 %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %72
72: ; preds = %56
%73 = load i32, i32* %11
%74 = add nsw i32 %73, 1
store i32 %74, i32* %11
br label %52
75: ; preds = %52
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define void @write_connnames(i32 %0, i8 signext %1, i8** nocapture %2, i32 %3) {
%5 = alloca i16
%6 = alloca [2 x i8]
%7 = alloca i16
%8 = bitcast i16* %5 to i8*
%9 = icmp sgt i32 %3, 0
br i1 %9, label %10, label %25
10: ; preds = %4
%11 = zext i32 %3 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %21, %12 ]
%14 = phi i16 [ 0, %10 ], [ %20, %12 ]
%15 = getelementptr inbounds i8*, i8** %2, i64 %13
%16 = load i8*, i8** %15
%17 = tail call i32 @strlen(i8* %16)
%18 = trunc i32 %17 to i16
%19 = add i16 %14, 1
%20 = add i16 %19, %18
%21 = add nuw nsw i64 %13, 1
%22 = icmp eq i64 %21, %11
br i1 %22, label %23, label %12
23: ; preds = %12
%24 = add i16 %20, 4
br label %25
25: ; preds = %23, %4
%26 = phi i16 [ 4, %4 ], [ %24, %23 ]
%27 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
store i8 0, i8* %27
%28 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
store i8 %1, i8* %28
%29 = bitcast i16* %7 to i8*
%30 = trunc i32 %3 to i16
%31 = tail call zeroext i16 @htons(i16 zeroext %30)
store i16 %31, i16* %7
%32 = tail call zeroext i16 @htons(i16 zeroext %26)
store i16 %32, i16* %5
%33 = call i32 (i32, ...) @write(i32 %0, i16* %5, i64 2)
%34 = call i32 (i32, ...) @write(i32 %0, [2 x i8]* %6, i64 2)
%35 = call i32 (i32, ...) @write(i32 %0, i16* %7, i64 2)
br i1 %9, label %36, label %47
36: ; preds = %25
%37 = zext i32 %3 to i64
br label %38
38: ; preds = %36, %38
%39 = phi i64 [ 0, %36 ], [ %45, %38 ]
%40 = getelementptr inbounds i8*, i8** %2, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 @strlen(i8* %41)
%43 = call i32 (i32, ...) @write(i32 %0, i8* %41, i32 %42)
%44 = call i32 (i32, ...) @write(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%45 = add nuw nsw i64 %39, 1
%46 = icmp eq i64 %45, %37
br i1 %46, label %47, label %38
47: ; preds = %38, %25
ret void
}