#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 getpid();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ syscall(int, int, int, char *);
int child_send(int pid[3]) {
  int i;
  for (i = 0; i < 3; i++) {
    if (pid[i] != getpid()) {
      char *send_buffer;
      send_buffer = (char *)malloc(6);
      send_buffer = "Hello";
      syscall(292, pid[i], sizeof(char *) * 6, send_buffer);
      printf("PID %d: Sent message to %d\n", getpid(), pid[i]);
    }
  }
}


x86 assembly (clang, -O0):
<child_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11e9 <child_send+0xa9>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
je     11d6 <child_send+0x96>
mov    $0x6,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe6c(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x20(%rbp),%rcx
mov    $0x124,%edi
mov    $0x30,%edx
call   1050 <syscall@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
jmp    11db <child_send+0x9b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1153 <child_send+0x13>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child_send>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
cmp    %eax,%ebp
je     118c <child_send+0x4c>
mov    $0x6,%edi
call   1060 <malloc@plt>
mov    (%rbx),%esi
lea    0xe9a(%rip),%rcx
mov    $0x124,%edi
mov    $0x30,%edx
call   1050 <syscall@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    (%rbx),%edx
lea    0xe81(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x4(%rbx),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
cmp    %eax,%ebp
je     11d5 <child_send+0x95>
mov    $0x6,%edi
call   1060 <malloc@plt>
mov    0x4(%rbx),%esi
lea    0xe52(%rip),%rcx
mov    $0x124,%edi
mov    $0x30,%edx
call   1050 <syscall@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    0x4(%rbx),%edx
lea    0xe38(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x8(%rbx),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
cmp    %eax,%ebp
je     121e <child_send+0xde>
mov    $0x6,%edi
call   1060 <malloc@plt>
mov    0x8(%rbx),%esi
lea    0xe09(%rip),%rcx
mov    $0x124,%edi
mov    $0x30,%edx
call   1050 <syscall@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    0x8(%rbx),%edx
lea    0xdef(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"Hello\00"
@.str.1 = [28 x i8] c"PID %d: Sent message to %d\0A\00"
define i32 @child_send(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = tail call i32 (...) @getpid()
%4 = icmp eq i32 %2, %3
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = tail call i64 @malloc(i32 6)
%7 = load i32, i32* %0
%8 = tail call i32 @syscall(i32 292, i32 %7, i32 48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 (...) @getpid()
%10 = load i32, i32* %0
%11 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %10)
br label %12
12: ; preds = %1, %5
%13 = getelementptr inbounds i32, i32* %0, i64 1
%14 = load i32, i32* %13
%15 = tail call i32 (...) @getpid()
%16 = icmp eq i32 %14, %15
br i1 %16, label %24, label %17
17: ; preds = %12
%18 = tail call i64 @malloc(i32 6)
%19 = load i32, i32* %13
%20 = tail call i32 @syscall(i32 292, i32 %19, i32 48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%21 = tail call i32 (...) @getpid()
%22 = load i32, i32* %13
%23 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %22)
br label %24
24: ; preds = %17, %12
%25 = getelementptr inbounds i32, i32* %0, i64 2
%26 = load i32, i32* %25
%27 = tail call i32 (...) @getpid()
%28 = icmp eq i32 %26, %27
br i1 %28, label %36, label %29
29: ; preds = %24
%30 = tail call i64 @malloc(i32 6)
%31 = load i32, i32* %25
%32 = tail call i32 @syscall(i32 292, i32 %31, i32 48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%33 = tail call i32 (...) @getpid()
%34 = load i32, i32* %25
%35 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %34)
br label %36
36: ; preds = %29, %24
ret i32 undef
}