#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*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void addtogroup(int groupinfo[][500], int grno, int fd) {
  int i;
  for (i = 0; i < 500; i++) {
    if (groupinfo[grno][i] == fd) {
      char rep[50] = "Already in group\n";
      write(fd, rep, strlen(rep));
      break;
    }
    if (groupinfo[grno][i] != -1) {
      continue;
    }
    groupinfo[grno][i] = fd;
    char rep[50] = "Added to group\n";
    write(fd, rep, strlen(rep));
    break;
  }
}


x86 assembly (clang, -O0):
<addtogroup>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1f4,-0x14(%rbp)
jge    1269 <addtogroup+0x139>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
imul   $0x7d0,%rcx,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x10(%rbp),%eax
jne    11c6 <addtogroup+0x96>
lea    -0x50(%rbp),%rdi
lea    0xe7a(%rip),%rsi
mov    $0x32,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x9c(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    1269 <addtogroup+0x139>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
imul   $0x7d0,%rcx,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
cmpl   $0xffffffff,(%rax,%rcx,4)
je     11eb <addtogroup+0xbb>
jmp    125b <addtogroup+0x12b>
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
imul   $0x7d0,%rcx,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
lea    -0x90(%rbp),%rdi
lea    0xe2b(%rip),%rsi
mov    $0x32,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0xac(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xac(%rbp),%edi
mov    -0xa8(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    1269 <addtogroup+0x139>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114c <addtogroup+0x1c>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addtogroup>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %edx,%ebx
movslq %esi,%rax
imul   $0x7d0,%rax,%rax
add    %rdi,%rax
add    $0x4,%rax
mov    $0x1f4,%ecx
nop
mov    -0x4(%rax),%edx
cmp    %ebx,%edx
je     1163 <addtogroup+0x43>
cmp    $0xffffffff,%edx
je     1184 <addtogroup+0x64>
mov    (%rax),%edx
cmp    %ebx,%edx
je     1163 <addtogroup+0x43>
cmp    $0xffffffff,%edx
je     1188 <addtogroup+0x68>
add    $0x8,%rax
add    $0xfffffffffffffffe,%rcx
jne    1140 <addtogroup+0x20>
jmp    11cb <addtogroup+0xab>
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe9a(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe7e(%rip),%xmm0
jmp    11a9 <addtogroup+0x89>
add    $0xfffffffffffffffc,%rax
mov    %ebx,(%rax)
movaps 0xecf(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeb3(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe97(%rip),%xmm0
movaps %xmm0,(%rsp)
movw   $0x0,0x30(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.addtogroup.rep = [50 x i8] c"Already in group\0A\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.addtogroup.rep.1 = [50 x i8] c"Added to group\0A\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
define void @addtogroup([500 x i32]* %0, i32 %1, i32 %2) {
%4 = alloca [500 x i32]*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [50 x i8]
%9 = alloca [50 x i8]
store [500 x i32]* %0, [500 x i32]** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %10
10: ; preds = %57, %3
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 500
br i1 %12, label %13, label %60
13: ; preds = %10
%14 = load [500 x i32]*, [500 x i32]** %4
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [500 x i32], [500 x i32]* %14, i64 %16
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [500 x i32], [500 x i32]* %17, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = load i32, i32* %6
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %31
24: ; preds = %13
%25 = bitcast [50 x i8]* %8 to i8*
%26 = load i32, i32* %6
%27 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%28 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = call i32 @write(i32 %26, i8* %27, i32 %29)
br label %60
31: ; preds = %13
%32 = load [500 x i32]*, [500 x i32]** %4
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [500 x i32], [500 x i32]* %32, i64 %34
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [500 x i32], [500 x i32]* %35, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = icmp ne i32 %39, -1
br i1 %40, label %41, label %42
41: ; preds = %31
br label %57
42: ; preds = %31
%43 = load i32, i32* %6
%44 = load [500 x i32]*, [500 x i32]** %4
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [500 x i32], [500 x i32]* %44, i64 %46
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [500 x i32], [500 x i32]* %47, i64 0, i64 %49
store i32 %43, i32* %50
%51 = bitcast [50 x i8]* %9 to i8*
%52 = load i32, i32* %6
%53 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%54 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%55 = call i32 @strlen(i8* %54)
%56 = call i32 @write(i32 %52, i8* %53, i32 %55)
br label %60
57: ; preds = %41
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %10
60: ; preds = %42, %24, %10
ret void
}

LLVM IR (-O2):
@__const.addtogroup.rep = [50 x i8] c"Already in group\0A\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.addtogroup.rep.1 = [50 x i8] c"Added to group\0A\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
define void @addtogroup([500 x i32]* nocapture %0, i32 %1, i32 %2) {
%4 = alloca [50 x i8]
%5 = alloca [50 x i8]
%6 = sext i32 %1 to i64
br label %17
7: ; preds = %26
%8 = or i64 %18, 1
%9 = getelementptr inbounds [500 x i32], [500 x i32]* %0, i64 %6, i64 %8
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, %2
br i1 %11, label %22, label %12
12: ; preds = %7
%13 = icmp eq i32 %10, -1
br i1 %13, label %28, label %14
14: ; preds = %12
%15 = add nuw nsw i64 %18, 2
%16 = icmp eq i64 %15, 500
br i1 %16, label %33, label %17
17: ; preds = %14, %3
%18 = phi i64 [ 0, %3 ], [ %15, %14 ]
%19 = getelementptr inbounds [500 x i32], [500 x i32]* %0, i64 %6, i64 %18
%20 = load i32, i32* %19
%21 = icmp eq i32 %20, %2
br i1 %21, label %22, label %26
22: ; preds = %7, %17
%23 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @write(i32 %2, i8* %23, i32 %24)
br label %33
26: ; preds = %17
%27 = icmp eq i32 %20, -1
br i1 %27, label %28, label %7
28: ; preds = %12, %26
%29 = phi i32* [ %19, %26 ], [ %9, %12 ]
store i32 %2, i32* %29
%30 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
%32 = call i32 @write(i32 %2, i8* %30, i32 %31)
br label %33
33: ; preds = %14, %28, %22
ret void
}