#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 */
struct sockaddr_un {
  int /*<<< orphan*/ sun_family;
  int /*<<< orphan*/ sun_path;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sa;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ distinti(int, int *);
void *malloc(int);
int /*<<< orphan*/ perror(char *);
int rand();
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
void create_addr(int k, int p, int *cs) {
  int i, j;
  struct sockaddr_un *sa = malloc(p * sizeof(struct sockaddr_un));
  int *chosen = malloc(p * sizeof(int));
  char s[15] = "OOB-server-";
  for (i = 0; i < p; i++) {
    chosen[i] = (rand() % k) + 1;
    while (!distinti(i, chosen))
      chosen[i] = (rand() % k) + 1;
    sprintf((s + 11), "%d\0", chosen[i]);
    strncpy(sa[i].sun_path, s, 108);
    sa[i].sun_family = AF_UNIX;
    if ((cs[i] = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
      perror("client: error creating socket");
    if (connect(cs[i], (struct sockaddr *)&(sa[i]), sizeof(sa[i])) == -1)
      perror("client: error connecting to socket");
  }
}


x86 assembly (clang, -O0):
<create_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    0xe41(%rip),%rax
mov    %rax,-0x37(%rbp)
mov    0xe3f(%rip),%eax
mov    %eax,-0x2f(%rbp)
mov    0xe39(%rip),%ax
mov    %ax,-0x2b(%rbp)
mov    0xe31(%rip),%al
mov    %al,-0x29(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    131d <create_addr+0x19d>
mov    $0x0,%al
call   1090 <rand@plt>
cltd
idivl  -0x4(%rbp)
add    $0x1,%edx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1040 <distinti@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    122d <create_addr+0xad>
jmp    124b <create_addr+0xcb>
mov    $0x0,%al
call   1090 <rand@plt>
cltd
idivl  -0x4(%rbp)
add    $0x1,%edx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    120c <create_addr+0x8c>
lea    -0x37(%rbp),%rdi
add    $0xb,%rdi
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdaa(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    0x4(%rax,%rcx,8),%edi
lea    -0x37(%rbp),%rsi
mov    $0x6c,%edx
call   1030 <strncpy@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,8)
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
mov    %eax,(%rcx,%rdx,4)
cmp    $0xffffffff,%eax
jne    12d1 <create_addr+0x151>
lea    0xd47(%rip),%rdi
call   1060 <perror@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x20(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    $0x8,%edx
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
jne    130a <create_addr+0x18a>
lea    0xd2c(%rip),%rdi
call   1060 <perror@plt>
jmp    130f <create_addr+0x18f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e7 <create_addr+0x67>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_addr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %esi,%r12d
mov    %edi,%ebp
lea    0x0(,%r12,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
lea    0x0(,%r12,4),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movabs $0x767265732d424f4f,%rax
65 72 76
mov    %rax,0x8(%rsp)
movq   $0x2d726576,0xf(%rsp)
72 2d
test   %r12d,%r12d
jle    129b <create_addr+0x11b>
mov    %r12d,%r12d
xor    %r13d,%r13d
jmp    11f0 <create_addr+0x70>
add    $0x1,%r13
cmp    %r12,%r13
je     129b <create_addr+0x11b>
nopl   0x0(%rax)
xor    %eax,%eax
call   1090 <rand@plt>
cltd
idiv   %ebp
add    $0x1,%edx
mov    %edx,(%rbx,%r13,4)
mov    %r13d,%edi
mov    %rbx,%rsi
call   1040 <distinti@plt>
test   %eax,%eax
je     11f0 <create_addr+0x70>
mov    (%rbx,%r13,4),%edx
lea    0x13(%rsp),%rdi
lea    0xdef(%rip),%rsi
call   1070 <sprintf@plt>
mov    0x4(%r15,%r13,8),%edi
lea    0x8(%rsp),%rsi
mov    $0x6c,%edx
call   1030 <strncpy@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
mov    %edi,(%r15,%r13,8)
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,(%r14,%r13,4)
cmp    $0xffffffff,%eax
je     1289 <create_addr+0x109>
lea    (%r15,%r13,8),%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
jne    11df <create_addr+0x5f>
lea    0xdb2(%rip),%rdi
call   1060 <perror@plt>
jmp    11df <create_addr+0x5f>
lea    0xd83(%rip),%rdi
call   1060 <perror@plt>
mov    (%r14,%r13,4),%eax
jmp    125f <create_addr+0xdf>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@__const.create_addr.s = [15 x i8] c"OOB-server-\00\00\00\00"
@.str = [4 x i8] c"%d\00\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [30 x i8] c"client: error creating socket\00"
@.str.2 = [35 x i8] c"client: error connecting to socket\00"
define void @create_addr(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_un*
%10 = alloca i32*
%11 = alloca [15 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 8
%15 = trunc i64 %14 to i32
%16 = call i8* @malloc(i32 %15)
%17 = bitcast i8* %16 to %struct.sockaddr_un*
store %struct.sockaddr_un* %17, %struct.sockaddr_un** %9
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 4
%21 = trunc i64 %20 to i32
%22 = call i8* @malloc(i32 %21)
%23 = bitcast i8* %22 to i32*
store i32* %23, i32** %10
%24 = bitcast [15 x i8]* %11 to i8*
store i32 0, i32* %7
br label %25
25: ; preds = %102, %3
%26 = load i32, i32* %7
%27 = load i32, i32* %5
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %105
29: ; preds = %25
%30 = call i32 (...) @rand()
%31 = load i32, i32* %4
%32 = srem i32 %30, %31
%33 = add nsw i32 %32, 1
%34 = load i32*, i32** %10
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
store i32 %33, i32* %37
br label %38
38: ; preds = %44, %29
%39 = load i32, i32* %7
%40 = load i32*, i32** %10
%41 = call i32 @distinti(i32 %39, i32* %40)
%42 = icmp ne i32 %41, 0
%43 = xor i1 %42, true
br i1 %43, label %44, label %53
44: ; preds = %38
%45 = call i32 (...) @rand()
%46 = load i32, i32* %4
%47 = srem i32 %45, %46
%48 = add nsw i32 %47, 1
%49 = load i32*, i32** %10
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
store i32 %48, i32* %52
br label %38
53: ; preds = %38
%54 = getelementptr inbounds [15 x i8], [15 x i8]* %11, i64 0, i64 0
%55 = getelementptr inbounds i8, i8* %54, i64 11
%56 = load i32*, i32** %10
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
%60 = load i32, i32* %59
%61 = call i32 @sprintf(i8* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %60)
%62 = load %struct.sockaddr_un*, %struct.sockaddr_un** %9
%63 = load i32, i32* %7
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %62, i64 %64
%66 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %65, i32 0, i32 1
%67 = load i32, i32* %66
%68 = getelementptr inbounds [15 x i8], [15 x i8]* %11, i64 0, i64 0
%69 = call i32 @strncpy(i32 %67, i8* %68, i32 108)
%70 = load i32, i32* @AF_UNIX
%71 = load %struct.sockaddr_un*, %struct.sockaddr_un** %9
%72 = load i32, i32* %7
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %71, i64 %73
%75 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %74, i32 0, i32 0
store i32 %70, i32* %75
%76 = load i32, i32* @AF_UNIX
%77 = load i32, i32* @SOCK_STREAM
%78 = call i32 @socket(i32 %76, i32 %77, i32 0)
%79 = load i32*, i32** %6
%80 = load i32, i32* %7
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %79, i64 %81
store i32 %78, i32* %82
%83 = icmp eq i32 %78, -1
br i1 %83, label %84, label %86
84: ; preds = %53
%85 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %86
86: ; preds = %84, %53
%87 = load i32*, i32** %6
%88 = load i32, i32* %7
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i32, i32* %87, i64 %89
%91 = load i32, i32* %90
%92 = load %struct.sockaddr_un*, %struct.sockaddr_un** %9
%93 = load i32, i32* %7
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %92, i64 %94
%96 = bitcast %struct.sockaddr_un* %95 to %struct.sockaddr*
%97 = call i32 @connect(i32 %91, %struct.sockaddr* %96, i32 8)
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %101
99: ; preds = %86
%100 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %101
101: ; preds = %99, %86
br label %102
102: ; preds = %101
%103 = load i32, i32* %7
%104 = add nsw i32 %103, 1
store i32 %104, i32* %7
br label %25
105: ; preds = %25
ret void
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@__const.create_addr.s = [15 x i8] c"OOB-server-\00\00\00\00"
@.str = [4 x i8] c"%d\00\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [30 x i8] c"client: error creating socket\00"
@.str.2 = [35 x i8] c"client: error connecting to socket\00"
define void @create_addr(i32 %0, i32 %1, i32* nocapture %2) {
%4 = alloca [15 x i8]
%5 = shl i32 %1, 3
%6 = tail call i8* @malloc(i32 %5)
%7 = bitcast i8* %6 to %struct.sockaddr_un*
%8 = shl i32 %1, 2
%9 = tail call i8* @malloc(i32 %8)
%10 = bitcast i8* %9 to i32*
%11 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %57
13: ; preds = %3
%14 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 11
%15 = zext i32 %1 to i64
br label %16
16: ; preds = %13, %54
%17 = phi i64 [ 0, %13 ], [ %55, %54 ]
%18 = call i32 (...) @rand()
%19 = getelementptr inbounds i32, i32* %10, i64 %17
%20 = srem i32 %18, %0
%21 = add nsw i32 %20, 1
store i32 %21, i32* %19
%22 = trunc i64 %17 to i32
%23 = call i32 @distinti(i32 %22, i32* %10)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %16, %25
%26 = call i32 (...) @rand()
%27 = srem i32 %26, %0
%28 = add nsw i32 %27, 1
store i32 %28, i32* %19
%29 = call i32 @distinti(i32 %22, i32* %10)
%30 = icmp eq i32 %29, 0
br i1 %30, label %25, label %31
31: ; preds = %25, %16
%32 = load i32, i32* %19
%33 = call i32 @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i64 %17
%35 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i64 %17, i32 1
%36 = load i32, i32* %35
%37 = call i32 @strncpy(i32 %36, i8* %11, i32 108)
%38 = load i32, i32* @AF_UNIX
%39 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %34, i64 0, i32 0
store i32 %38, i32* %39
%40 = load i32, i32* @SOCK_STREAM
%41 = call i32 @socket(i32 %38, i32 %40, i32 0)
%42 = getelementptr inbounds i32, i32* %2, i64 %17
store i32 %41, i32* %42
%43 = icmp eq i32 %41, -1
br i1 %43, label %44, label %47
44: ; preds = %31
%45 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%46 = load i32, i32* %42
br label %47
47: ; preds = %44, %31
%48 = phi i32 [ %46, %44 ], [ %41, %31 ]
%49 = bitcast %struct.sockaddr_un* %34 to %struct.sockaddr*
%50 = call i32 @connect(i32 %48, %struct.sockaddr* %49, i32 8)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %54
54: ; preds = %47, %52
%55 = add nuw nsw i64 %17, 1
%56 = icmp eq i64 %55, %15
br i1 %56, label %57, label %16
57: ; preds = %54, %3
ret void
}