#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__ in_array(int, int *, int);
int subset_it_id_for_idx(int, int *, int);
void triangles_with_common_edges(int n, int *triangle, int *res_triangles) {
  int i, t_id = 0;
  for (i = 0; i < n; i++) {
    int invalid_triangle[3];
    if (in_array(i, triangle, 3)) {
      continue;
    }
    int t;
    for (t = 0; t < 3; t++) {
      invalid_triangle[0] = i;
      invalid_triangle[1] = triangle[t];
      invalid_triangle[2] = triangle[(t + 1) % 3];
      res_triangles[t_id++] = subset_it_id_for_idx(n, invalid_triangle, 3);
    }
  }
}


x86 assembly (clang, -O0):
<triangles_with_common_edges>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11fe <triangles_with_common_edges+0xde>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x3,%edx
call   1040 <in_array@plt>
cmp    $0x0,%rax
je     116d <triangles_with_common_edges+0x4d>
jmp    11f0 <triangles_with_common_edges+0xd0>
movl   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x30(%rbp)
jge    11eb <triangles_with_common_edges+0xcb>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    -0x38(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x3,%edx
call   1030 <subset_it_id_for_idx@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1174 <triangles_with_common_edges+0x54>
jmp    11f0 <triangles_with_common_edges+0xd0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1141 <triangles_with_common_edges+0x21>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<triangles_with_common_edges>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
jle    11f3 <triangles_with_common_edges+0xd3>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r12d
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    115c <triangles_with_common_edges+0x3c>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %ebp,%r12d
je     11f3 <triangles_with_common_edges+0xd3>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1040 <in_array@plt>
test   %rax,%rax
jne    1150 <triangles_with_common_edges+0x30>
movslq %r15d,%r13
mov    %ebp,0xc(%rsp)
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    0x4(%rbx),%eax
mov    %eax,0x14(%rsp)
mov    %r12d,%edi
lea    0xc(%rsp),%r15
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <subset_it_id_for_idx@plt>
mov    %eax,(%r14,%r13,4)
mov    %ebp,0xc(%rsp)
mov    0x4(%rbx),%eax
mov    %eax,0x10(%rsp)
mov    0x8(%rbx),%eax
mov    %eax,0x14(%rsp)
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <subset_it_id_for_idx@plt>
mov    %eax,0x4(%r14,%r13,4)
mov    %ebp,0xc(%rsp)
mov    0x8(%rbx),%eax
mov    %eax,0x10(%rsp)
mov    (%rbx),%eax
mov    %eax,0x14(%rsp)
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <subset_it_id_for_idx@plt>
lea    0x3(%r13),%r15d
mov    %eax,0x8(%r14,%r13,4)
jmp    1150 <triangles_with_common_edges+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @triangles_with_common_edges(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [3 x i32]
%10 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 0, i32* %8
store i32 0, i32* %7
br label %11
11: ; preds = %54, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %57
15: ; preds = %11
%16 = load i32, i32* %7
%17 = load i32*, i32** %5
%18 = call i64 @in_array(i32 %16, i32* %17, i32 3)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
br label %54
21: ; preds = %15
store i32 0, i32* %10
br label %22
22: ; preds = %50, %21
%23 = load i32, i32* %10
%24 = icmp slt i32 %23, 3
br i1 %24, label %25, label %53
25: ; preds = %22
%26 = load i32, i32* %7
%27 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 0
store i32 %26, i32* %27
%28 = load i32*, i32** %5
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 1
store i32 %32, i32* %33
%34 = load i32*, i32** %5
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
%37 = srem i32 %36, 3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %34, i64 %38
%40 = load i32, i32* %39
%41 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 2
store i32 %40, i32* %41
%42 = load i32, i32* %4
%43 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 0
%44 = call i32 @subset_it_id_for_idx(i32 %42, i32* %43, i32 3)
%45 = load i32*, i32** %6
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i32, i32* %45, i64 %48
store i32 %44, i32* %49
br label %50
50: ; preds = %25
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %22
53: ; preds = %22
br label %54
54: ; preds = %53, %20
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %11
57: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @triangles_with_common_edges(i32 %0, i32* %1, i32* nocapture writeonly %2) {
%4 = alloca [3 x i32]
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %39
6: ; preds = %3
%7 = bitcast [3 x i32]* %4 to i8*
%8 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%9 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 1
%10 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 2
%11 = getelementptr inbounds i32, i32* %1, i64 1
%12 = getelementptr inbounds i32, i32* %1, i64 2
br label %13
13: ; preds = %6, %35
%14 = phi i32 [ 0, %6 ], [ %36, %35 ]
%15 = phi i32 [ 0, %6 ], [ %37, %35 ]
%16 = call i64 @in_array(i32 %15, i32* %1, i32 3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %35
18: ; preds = %13
%19 = sext i32 %14 to i64
store i32 %15, i32* %8
%20 = load i32, i32* %1
store i32 %20, i32* %9
%21 = load i32, i32* %11
store i32 %21, i32* %10
%22 = call i32 @subset_it_id_for_idx(i32 %0, i32* %8, i32 3)
%23 = add nsw i64 %19, 1
%24 = getelementptr inbounds i32, i32* %2, i64 %19
store i32 %22, i32* %24
store i32 %15, i32* %8
%25 = load i32, i32* %11
store i32 %25, i32* %9
%26 = load i32, i32* %12
store i32 %26, i32* %10
%27 = call i32 @subset_it_id_for_idx(i32 %0, i32* %8, i32 3)
%28 = add nsw i64 %19, 2
%29 = getelementptr inbounds i32, i32* %2, i64 %23
store i32 %27, i32* %29
store i32 %15, i32* %8
%30 = load i32, i32* %12
store i32 %30, i32* %9
%31 = load i32, i32* %1
store i32 %31, i32* %10
%32 = call i32 @subset_it_id_for_idx(i32 %0, i32* %8, i32 3)
%33 = add i32 %14, 3
%34 = getelementptr inbounds i32, i32* %2, i64 %28
store i32 %32, i32* %34
br label %35
35: ; preds = %18, %13
%36 = phi i32 [ %14, %13 ], [ %33, %18 ]
%37 = add nuw nsw i32 %15, 1
%38 = icmp eq i32 %37, %0
br i1 %38, label %39, label %13
39: ; preds = %35, %3
ret void
}