#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 BUFSIZ;
int /*<<< orphan*/ destroy_all_readers(int, int *, char const *, char const *);
int *malloc_or_die(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int open_udp(char const *, char const *, int *, int, int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int *create_all_readers(int cpus, const char *node, const char *port,
                        int pagesize, int fd) {
  char buf[BUFSIZ];
  int *port_array;
  int *pid_array;
  int start_port;
  int udp_port;
  int cpu;
  int pid;
  port_array = malloc_or_die(sizeof(int) * cpus);
  pid_array = malloc_or_die(sizeof(int) * cpus);
  memset(pid_array, 0, sizeof(int) * cpus);
  start_port = 1500;
  for (cpu = 0; cpu < cpus; cpu++) {
    udp_port = open_udp(node, port, &pid, cpu, pagesize, start_port);
    if (udp_port < 0)
      goto out_free;
    port_array[cpu] = udp_port;
    pid_array[cpu] = pid;
    start_port = udp_port + 1;
  }
  for (cpu = 0; cpu < cpus; cpu++) {
    snprintf(buf, BUFSIZ, "%s%d", cpu ? "," : "", port_array[cpu]);
    write(fd, buf, strlen(buf));
  }
  write(fd, "\0", 1);
  return pid_array;
out_free:
  destroy_all_readers(cpus, pid_array, node, port);
  return NULL;
}


x86 assembly (clang, -O0):
<create_all_readers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc_or_die@plt>
mov    %rax,-0x40(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc_or_die@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
movl   $0x5dc,-0x4c(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    126c <create_all_readers+0xfc>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x54(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x4c(%rbp),%r9d
lea    -0x58(%rbp),%rdx
call   1080 <open_udp@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jge    1239 <create_all_readers+0xc9>
jmp    130f <create_all_readers+0x19f>
mov    -0x50(%rbp),%edx
mov    -0x40(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x58(%rbp),%edx
mov    -0x48(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11ff <create_all_readers+0x8f>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12e7 <create_all_readers+0x177>
mov    -0x68(%rbp),%rdi
mov    0x2d56(%rip),%rax
mov    (%rax),%esi
mov    -0x54(%rbp),%edx
lea    0xd70(%rip),%rcx
lea    0xd68(%rip),%rax
cmp    $0x0,%edx
cmovne %rax,%rcx
mov    -0x40(%rbp),%rax
movslq -0x54(%rbp),%rdx
mov    (%rax,%rdx,4),%r8d
lea    0xd49(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x68(%rbp),%rdi
mov    -0x28(%rbp),%eax
mov    %eax,-0x6c(%rbp)
call   1040 <strlen@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1273 <create_all_readers+0x103>
mov    -0x28(%rbp),%edi
lea    0xd16(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    1332 <create_all_readers+0x1c2>
mov    -0xc(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1060 <destroy_all_readers@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_all_readers>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8d,-0x2c(%rbp)
mov    %ecx,%ebx
mov    %rdx,-0x50(%rbp)
mov    %rsi,-0x48(%rbp)
mov    %edi,%r13d
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    0x0(,%r13,4),%r15d
mov    %r15d,%edi
call   1090 <malloc_or_die@plt>
mov    %rax,%r12
mov    %r15d,%edi
call   1090 <malloc_or_die@plt>
mov    %rax,-0x38(%rbp)
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1070 <memset@plt>
test   %r13d,%r13d
jle    1289 <create_all_readers+0x119>
mov    %r13,-0x58(%rbp)
mov    %r13d,%r13d
mov    $0x5dc,%eax
xor    %r15d,%r15d
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
mov    %r15d,%ecx
mov    %ebx,%r8d
mov    %eax,%r9d
call   1080 <open_udp@plt>
test   %eax,%eax
js     129f <create_all_readers+0x12f>
mov    %eax,(%r12,%r15,4)
mov    -0x3c(%rbp),%ecx
mov    -0x38(%rbp),%rdx
mov    %ecx,(%rdx,%r15,4)
add    $0x1,%eax
add    $0x1,%r15
cmp    %r15,%r13
jne    11f0 <create_all_readers+0x80>
cmpl   $0x0,-0x58(%rbp)
mov    0x2da8(%rip),%r15
jle    1289 <create_all_readers+0x119>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r15),%esi
test   %rbx,%rbx
lea    0xdb8(%rip),%rcx
lea    0xdb2(%rip),%rdx
cmove  %rdx,%rcx
mov    (%r12,%rbx,4),%r8d
mov    %r14,%rdi
lea    0xd9a(%rip),%rdx
call   1050 <snprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1240 <create_all_readers+0xd0>
lea    0xd77(%rip),%rsi
mov    -0x2c(%rbp),%edi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    12b9 <create_all_readers+0x149>
mov    %r13d,%edi
mov    -0x38(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rcx
call   1060 <destroy_all_readers@plt>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [5 x i8] c"%s%d\00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] zeroinitializer
define i32* @create_all_readers(i32 %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i32 %0, i32* %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%21 = load i32, i32* @BUFSIZ
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %12
%24 = alloca i8, i64 %22
store i64 %22, i64* %13
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = mul i64 4, %26
%28 = trunc i64 %27 to i32
%29 = call i32* @malloc_or_die(i32 %28)
store i32* %29, i32** %14
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = mul i64 4, %31
%33 = trunc i64 %32 to i32
%34 = call i32* @malloc_or_die(i32 %33)
store i32* %34, i32** %15
%35 = load i32*, i32** %15
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = mul i64 4, %37
%39 = trunc i64 %38 to i32
%40 = call i32 @memset(i32* %35, i32 0, i32 %39)
store i32 1500, i32* %16
store i32 0, i32* %18
br label %41
41: ; preds = %68, %5
%42 = load i32, i32* %18
%43 = load i32, i32* %7
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %71
45: ; preds = %41
%46 = load i8*, i8** %8
%47 = load i8*, i8** %9
%48 = load i32, i32* %18
%49 = load i32, i32* %10
%50 = load i32, i32* %16
%51 = call i32 @open_udp(i8* %46, i8* %47, i32* %19, i32 %48, i32 %49, i32 %50)
store i32 %51, i32* %17
%52 = load i32, i32* %17
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %45
br label %98
55: ; preds = %45
%56 = load i32, i32* %17
%57 = load i32*, i32** %14
%58 = load i32, i32* %18
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
store i32 %56, i32* %60
%61 = load i32, i32* %19
%62 = load i32*, i32** %15
%63 = load i32, i32* %18
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %62, i64 %64
store i32 %61, i32* %65
%66 = load i32, i32* %17
%67 = add nsw i32 %66, 1
store i32 %67, i32* %16
br label %68
68: ; preds = %55
%69 = load i32, i32* %18
%70 = add nsw i32 %69, 1
store i32 %70, i32* %18
br label %41
71: ; preds = %41
store i32 0, i32* %18
br label %72
72: ; preds = %91, %71
%73 = load i32, i32* %18
%74 = load i32, i32* %7
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %94
76: ; preds = %72
%77 = load i32, i32* @BUFSIZ
%78 = load i32, i32* %18
%79 = icmp ne i32 %78, 0
%80 = zext i1 %79 to i64
%81 = select i1 %79, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%82 = load i32*, i32** %14
%83 = load i32, i32* %18
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i32, i32* %82, i64 %84
%86 = load i32, i32* %85
%87 = call i32 @snprintf(i8* %24, i32 %77, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %81, i32 %86)
%88 = load i32, i32* %11
%89 = call i32 @strlen(i8* %24)
%90 = call i32 @write(i32 %88, i8* %24, i32 %89)
br label %91
91: ; preds = %76
%92 = load i32, i32* %18
%93 = add nsw i32 %92, 1
store i32 %93, i32* %18
br label %72
94: ; preds = %72
%95 = load i32, i32* %11
%96 = call i32 @write(i32 %95, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%97 = load i32*, i32** %15
store i32* %97, i32** %6
store i32 1, i32* %20
br label %104
98: ; preds = %54
%99 = load i32, i32* %7
%100 = load i32*, i32** %15
%101 = load i8*, i8** %8
%102 = load i8*, i8** %9
%103 = call i32 @destroy_all_readers(i32 %99, i32* %100, i8* %101, i8* %102)
store i32* null, i32** %6
store i32 1, i32* %20
br label %104
104: ; preds = %98, %94
%105 = load i8*, i8** %12
%106 = load i32*, i32** %6
ret i32* %106
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [5 x i8] c"%s%d\00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] zeroinitializer
define i32* @create_all_readers(i32 %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = load i32, i32* @BUFSIZ
%8 = zext i32 %7 to i64
%9 = alloca i8, i64 %8
%10 = bitcast i32* %6 to i8*
%11 = shl i32 %0, 2
%12 = tail call i32* @malloc_or_die(i32 %11)
%13 = tail call i32* @malloc_or_die(i32 %11)
%14 = tail call i32 @memset(i32* %13, i32 0, i32 %11)
%15 = icmp sgt i32 %0, 0
br i1 %15, label %16, label %46
16: ; preds = %5
%17 = zext i32 %0 to i64
br label %21
18: ; preds = %27
br i1 %15, label %19, label %46
19: ; preds = %18
%20 = zext i32 %0 to i64
br label %34
21: ; preds = %16, %27
%22 = phi i64 [ 0, %16 ], [ %32, %27 ]
%23 = phi i32 [ 1500, %16 ], [ %31, %27 ]
%24 = trunc i64 %22 to i32
%25 = call i32 @open_udp(i8* %1, i8* %2, i32* %6, i32 %24, i32 %3, i32 %23)
%26 = icmp slt i32 %25, 0
br i1 %26, label %48, label %27
27: ; preds = %21
%28 = getelementptr inbounds i32, i32* %12, i64 %22
store i32 %25, i32* %28
%29 = load i32, i32* %6
%30 = getelementptr inbounds i32, i32* %13, i64 %22
store i32 %29, i32* %30
%31 = add nuw nsw i32 %25, 1
%32 = add nuw nsw i64 %22, 1
%33 = icmp eq i64 %32, %17
br i1 %33, label %18, label %21
34: ; preds = %19, %34
%35 = phi i64 [ 0, %19 ], [ %44, %34 ]
%36 = load i32, i32* @BUFSIZ
%37 = icmp eq i64 %35, 0
%38 = select i1 %37, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%39 = getelementptr inbounds i32, i32* %12, i64 %35
%40 = load i32, i32* %39
%41 = call i32 @snprintf(i8* %9, i32 %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %38, i32 %40)
%42 = call i32 @strlen(i8* %9)
%43 = call i32 @write(i32 %4, i8* %9, i32 %42)
%44 = add nuw nsw i64 %35, 1
%45 = icmp eq i64 %44, %20
br i1 %45, label %46, label %34
46: ; preds = %34, %5, %18
%47 = call i32 @write(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
br label %50
48: ; preds = %21
%49 = call i32 @destroy_all_readers(i32 %0, i32* %13, i8* %1, i8* %2)
br label %50
50: ; preds = %48, %46
%51 = phi i32* [ null, %48 ], [ %13, %46 ]
ret i32* %51
}