#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 */

/* Variables and functions */
int /*<<< orphan*/ error(char *);
int write(int const, char const *, int);
void send_to_sockets(const int *sockets, const char msg[256],
                     const int num_of_sockets) {
  for (size_t i = 0; i < num_of_sockets; i++) {
    if (sockets[i] > 0) {
      int ret = write(sockets[i], msg, 256);
      if (ret < 0)
        error("ERROR writing to socket");
    }
  }
}


x86 assembly (clang, -O0):
<send_to_sockets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
jae    11ab <send_to_sockets+0x8b>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jle    1195 <send_to_sockets+0x75>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1190 <send_to_sockets+0x70>
lea    0xe75(%rip),%rdi
call   1040 <error@plt>
jmp    1195 <send_to_sockets+0x75>
jmp    119a <send_to_sockets+0x7a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113b <send_to_sockets+0x1b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_to_sockets>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %edx,%edx
je     117c <send_to_sockets+0x5c>
mov    %rsi,%r14
mov    %rdi,%r12
movslq %edx,%r13
xor    %ebx,%ebx
lea    0xec1(%rip),%r15
jmp    1159 <send_to_sockets+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r13
je     117c <send_to_sockets+0x5c>
mov    (%r12,%rbx,4),%edi
test   %edi,%edi
jle    1150 <send_to_sockets+0x30>
mov    %r14,%rsi
mov    $0x100,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    1150 <send_to_sockets+0x30>
mov    %r15,%rdi
call   1040 <error@plt>
jmp    1150 <send_to_sockets+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"ERROR writing to socket\00"
define void @send_to_sockets(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i64 0, i64* %7
br label %9
9: ; preds = %33, %3
%10 = load i64, i64* %7
%11 = load i32, i32* %6
%12 = sext i32 %11 to i64
%13 = icmp ult i64 %10, %12
br i1 %13, label %14, label %36
14: ; preds = %9
%15 = load i32*, i32** %4
%16 = load i64, i64* %7
%17 = getelementptr inbounds i32, i32* %15, i64 %16
%18 = load i32, i32* %17
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %14
%21 = load i32*, i32** %4
%22 = load i64, i64* %7
%23 = getelementptr inbounds i32, i32* %21, i64 %22
%24 = load i32, i32* %23
%25 = load i8*, i8** %5
%26 = call i32 @write(i32 %24, i8* %25, i32 256)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %20
%30 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29, %20
br label %32
32: ; preds = %31, %14
br label %33
33: ; preds = %32
%34 = load i64, i64* %7
%35 = add i64 %34, 1
store i64 %35, i64* %7
br label %9
36: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"ERROR writing to socket\00"
define void @send_to_sockets(i32* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = sext i32 %2 to i64
br label %8
7: ; preds = %18, %3
ret void
8: ; preds = %5, %18
%9 = phi i64 [ %19, %18 ], [ 0, %5 ]
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = tail call i32 @write(i32 %11, i8* %1, i32 256)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %13, %16, %8
%19 = add nuw i64 %9, 1
%20 = icmp eq i64 %19, %6
br i1 %20, label %7, label %8
}