#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 */
typedef int uint64_t;
typedef int uint32_t;

/* Variables and functions */
int gcd_three(int *);
uint64_t find_class(uint32_t *triangle, size_t n) {
  uint32_t abc_gcd = gcd_three(triangle);
  for (size_t i = 0; i < 3; i++) {
    triangle[i] /= abc_gcd;
  }
  return (
      ((3 * triangle[0] + 5 * triangle[1] + 7 * triangle[2]) % 15000000047) %
      n);
}


x86 assembly (clang, -O0):
<find_class>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <gcd_three@plt>
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x3,-0x20(%rbp)
jae    116e <find_class+0x5e>
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x28(%rbp),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1134 <find_class+0x24>
mov    -0x8(%rbp),%rax
imul   $0x3,(%rax),%eax
mov    -0x8(%rbp),%rcx
imul   $0x5,0x4(%rcx),%ecx
add    %ecx,%eax
mov    -0x8(%rbp),%rcx
imul   $0x7,0x8(%rcx),%ecx
add    %ecx,%eax
cltq
movabs $0x37e11d62f,%rcx
cqto
idiv   %rcx
mov    %rdx,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %edx,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_class>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <gcd_three@plt>
mov    %eax,%ecx
mov    (%rbx),%eax
mov    0x4(%rbx),%esi
cltd
idiv   %ecx
mov    %eax,%edi
mov    %eax,(%rbx)
mov    %esi,%eax
cltd
idiv   %ecx
mov    %eax,%esi
mov    %eax,0x4(%rbx)
mov    0x8(%rbx),%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    %eax,0x8(%rbx)
lea    (%rdi,%rdi,2),%eax
lea    (%rsi,%rsi,4),%edx
add    %eax,%edx
lea    0x0(,%rcx,8),%eax
sub    %ecx,%eax
add    %edx,%eax
movslq %eax,%rcx
mov    %rcx,%rdx
or     %r14,%rdx
shr    $0x20,%rdx
je     1171 <find_class+0x61>
mov    %rcx,%rax
xor    %edx,%edx
div    %r14
mov    %rdx,%rax
jmp    1178 <find_class+0x68>
xor    %edx,%edx
div    %r14d
mov    %edx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @find_class(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
store i32* %0, i32** %3
store i64 %1, i64* %4
%7 = load i32*, i32** %3
%8 = call i32 @gcd_three(i32* %7)
store i32 %8, i32* %5
store i64 0, i64* %6
br label %9
9: ; preds = %19, %2
%10 = load i64, i64* %6
%11 = icmp ult i64 %10, 3
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i32, i32* %5
%14 = load i32*, i32** %3
%15 = load i64, i64* %6
%16 = getelementptr inbounds i32, i32* %14, i64 %15
%17 = load i32, i32* %16
%18 = sdiv i32 %17, %13
store i32 %18, i32* %16
br label %19
19: ; preds = %12
%20 = load i64, i64* %6
%21 = add i64 %20, 1
store i64 %21, i64* %6
br label %9
22: ; preds = %9
%23 = load i32*, i32** %3
%24 = getelementptr inbounds i32, i32* %23, i64 0
%25 = load i32, i32* %24
%26 = mul nsw i32 3, %25
%27 = load i32*, i32** %3
%28 = getelementptr inbounds i32, i32* %27, i64 1
%29 = load i32, i32* %28
%30 = mul nsw i32 5, %29
%31 = add nsw i32 %26, %30
%32 = load i32*, i32** %3
%33 = getelementptr inbounds i32, i32* %32, i64 2
%34 = load i32, i32* %33
%35 = mul nsw i32 7, %34
%36 = add nsw i32 %31, %35
%37 = sext i32 %36 to i64
%38 = srem i64 %37, 15000000047
%39 = load i64, i64* %4
%40 = urem i64 %38, %39
%41 = trunc i64 %40 to i32
ret i32 %41
}

LLVM IR (-O2):
define i32 @find_class(i32* %0, i64 %1) {
%3 = tail call i32 @gcd_three(i32* %0)
%4 = load i32, i32* %0
%5 = sdiv i32 %4, %3
store i32 %5, i32* %0
%6 = getelementptr inbounds i32, i32* %0, i64 1
%7 = load i32, i32* %6
%8 = sdiv i32 %7, %3
store i32 %8, i32* %6
%9 = getelementptr inbounds i32, i32* %0, i64 2
%10 = load i32, i32* %9
%11 = sdiv i32 %10, %3
store i32 %11, i32* %9
%12 = mul nsw i32 %5, 3
%13 = mul nsw i32 %8, 5
%14 = add nsw i32 %13, %12
%15 = mul nsw i32 %11, 7
%16 = add nsw i32 %14, %15
%17 = sext i32 %16 to i64
%18 = urem i64 %17, %1
%19 = trunc i64 %18 to i32
ret i32 %19
}