#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*/ perror(char *);
scalar_t__ write(int, void const *, size_t);
int spray_skbuff(int ss[4][2], const void *buf, size_t size) {
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 128; j++) {
      if (write(ss[i][0], buf, size) < 0) {
        perror("[-] write");
        return -1;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<spray_skbuff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    11b9 <spray_skbuff+0x99>
movl   $0x0,-0x28(%rbp)
cmpl   $0x80,-0x28(%rbp)
jge    11a6 <spray_skbuff+0x86>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1193 <spray_skbuff+0x73>
lea    0xe7e(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c0 <spray_skbuff+0xa0>
jmp    1198 <spray_skbuff+0x78>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    114c <spray_skbuff+0x2c>
jmp    11ab <spray_skbuff+0x8b>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113b <spray_skbuff+0x1b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spray_skbuff>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x80,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx),%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <write@plt>
test   %rax,%rax
js     11bc <spray_skbuff+0x9c>
add    $0xffffffff,%ebp
jne    1140 <spray_skbuff+0x20>
mov    $0x80,%ebp
nopl   0x0(%rax)
mov    0x8(%rbx),%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <write@plt>
test   %rax,%rax
js     11bc <spray_skbuff+0x9c>
add    $0xffffffff,%ebp
jne    1160 <spray_skbuff+0x40>
mov    $0x80,%ebp
nopl   (%rax)
mov    0x10(%rbx),%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <write@plt>
test   %rax,%rax
js     11bc <spray_skbuff+0x9c>
add    $0xffffffff,%ebp
jne    1180 <spray_skbuff+0x60>
mov    $0x80,%ebp
nopl   (%rax)
mov    0x18(%rbx),%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <write@plt>
test   %rax,%rax
js     11bc <spray_skbuff+0x9c>
add    $0xffffffff,%ebp
jne    11a0 <spray_skbuff+0x80>
xor    %eax,%eax
jmp    11cd <spray_skbuff+0xad>
lea    0xe3d(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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