#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ readUpdate(int, long *, int *);
int readRights(int fd, long count, size_t count_len, int **fds,
               int msi_vectors) {
  int j, newfd;
  for (;;) {
    long posn = 0;
    readUpdate(fd, &posn, &newfd);
    printf("reading posn %ld ", posn);
    fds[posn] = (int *)malloc(msi_vectors * sizeof(int));
    fds[posn][0] = newfd;
    for (j = 1; j < msi_vectors; j++) {
      readUpdate(fd, &posn, &newfd);
      fds[posn][j] = newfd;
      printf("%d.", fds[posn][j]);
    }
    printf("\n");
    if (posn == count)
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<readRights>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1050 <readUpdate@plt>
mov    -0x38(%rbp),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rdx
mov    (%rax,%rdx,8),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    120c <readRights+0xdc>
mov    -0x4(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1050 <readUpdate@plt>
mov    -0x2c(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ab <readRights+0x7b>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    122d <readRights+0xfd>
jmp    1232 <readRights+0x102>
jmp    114b <readRights+0x1b>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readRights>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%rbx
mov    %rsi,0x18(%rsp)
mov    %edi,%ebp
lea    0x0(,%r8,4),%eax
mov    %eax,0xc(%rsp)
mov    %r8,0x20(%rsp)
mov    %r8d,%eax
mov    %rax,0x10(%rsp)
mov    %rsp,%r15
lea    0x8(%rsp),%r14
mov    0x10(%rsp),%r13
jmp    1199 <readRights+0x59>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x18(%rsp),%rax
cmp    %rax,(%rsp)
je     1229 <readRights+0xe9>
movq   $0x0,(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <readUpdate@plt>
mov    (%rsp),%rsi
lea    0xe47(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%edi
call   1050 <malloc@plt>
mov    (%rsp),%rcx
mov    %rax,(%rbx,%rcx,8)
mov    0x8(%rsp),%ecx
mov    %ecx,(%rax)
cmpl   $0x2,0x20(%rsp)
jl     1180 <readRights+0x40>
mov    $0x1,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <readUpdate@plt>
mov    0x8(%rsp),%esi
mov    (%rsp),%rax
mov    (%rbx,%rax,8),%rax
mov    %esi,(%rax,%r12,4)
lea    0xdfe(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r12
cmp    %r12,%r13
jne    11f0 <readRights+0xb0>
jmp    1180 <readRights+0x40>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"reading posn %ld \00"
@.str.1 = [4 x i8] c"%d.\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @readRights(i32 %0, i64 %1, i64 %2, i32** %3, i32 %4) {
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32**
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
store i32 %0, i32* %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i32** %3, i32*** %9
store i32 %4, i32* %10
br label %14
14: ; preds = %67, %5
store i64 0, i64* %13
%15 = load i32, i32* %6
%16 = call i32 @readUpdate(i32 %15, i64* %13, i32* %12)
%17 = load i64, i64* %13
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 %17)
%19 = load i32, i32* %10
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 4
%22 = trunc i64 %21 to i32
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i32*
%25 = load i32**, i32*** %9
%26 = load i64, i64* %13
%27 = getelementptr inbounds i32*, i32** %25, i64 %26
store i32* %24, i32** %27
%28 = load i32, i32* %12
%29 = load i32**, i32*** %9
%30 = load i64, i64* %13
%31 = getelementptr inbounds i32*, i32** %29, i64 %30
%32 = load i32*, i32** %31
%33 = getelementptr inbounds i32, i32* %32, i64 0
store i32 %28, i32* %33
store i32 1, i32* %11
br label %34
34: ; preds = %58, %14
%35 = load i32, i32* %11
%36 = load i32, i32* %10
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %61
38: ; preds = %34
%39 = load i32, i32* %6
%40 = call i32 @readUpdate(i32 %39, i64* %13, i32* %12)
%41 = load i32, i32* %12
%42 = load i32**, i32*** %9
%43 = load i64, i64* %13
%44 = getelementptr inbounds i32*, i32** %42, i64 %43
%45 = load i32*, i32** %44
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
store i32 %41, i32* %48
%49 = load i32**, i32*** %9
%50 = load i64, i64* %13
%51 = getelementptr inbounds i32*, i32** %49, i64 %50
%52 = load i32*, i32** %51
%53 = load i32, i32* %11
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
%56 = load i32, i32* %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %38
%59 = load i32, i32* %11
%60 = add nsw i32 %59, 1
store i32 %60, i32* %11
br label %34
61: ; preds = %34
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%63 = load i64, i64* %13
%64 = load i64, i64* %7
%65 = icmp eq i64 %63, %64
br i1 %65, label %66, label %67
66: ; preds = %61
br label %68
67: ; preds = %61
br label %14
68: ; preds = %66
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"reading posn %ld \00"
@.str.1 = [4 x i8] c"%d.\00"
define i32 @readRights(i32 %0, i64 %1, i64 %2, i32** nocapture %3, i32 %4) {
%6 = alloca i32
%7 = alloca i64
%8 = bitcast i32* %6 to i8*
%9 = bitcast i64* %7 to i8*
%10 = shl i32 %4, 2
%11 = icmp sgt i32 %4, 1
%12 = zext i32 %4 to i64
br label %13
13: ; preds = %33, %5
store i64 0, i64* %7
%14 = call i32 @readUpdate(i32 %0, i64* %7, i32* %6)
%15 = load i64, i64* %7
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 %15)
%17 = call i64 @malloc(i32 %10)
%18 = inttoptr i64 %17 to i32*
%19 = load i64, i64* %7
%20 = getelementptr inbounds i32*, i32** %3, i64 %19
store i32* %18, i32** %20
%21 = load i32, i32* %6
store i32 %21, i32* %18
br i1 %11, label %22, label %33
22: ; preds = %13, %22
%23 = phi i64 [ %31, %22 ], [ 1, %13 ]
%24 = call i32 @readUpdate(i32 %0, i64* %7, i32* %6)
%25 = load i32, i32* %6
%26 = load i64, i64* %7
%27 = getelementptr inbounds i32*, i32** %3, i64 %26
%28 = load i32*, i32** %27
%29 = getelementptr inbounds i32, i32* %28, i64 %23
store i32 %25, i32* %29
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%31 = add nuw nsw i64 %23, 1
%32 = icmp eq i64 %31, %12
br i1 %32, label %33, label %22
33: ; preds = %22, %13
%34 = call i32 @putchar(i32 10)
%35 = load i64, i64* %7
%36 = icmp eq i64 %35, %1
br i1 %36, label %37, label %13
37: ; preds = %33
ret i32 0
}