#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 extended_gcd(unsigned long, int, int *, int *);
unsigned long solve(int N) {
  unsigned long res = 1;
  for (int i = 2; i <= N; ++i) {
    int u, v;
    res = (i * res / extended_gcd(res, i, &u, &v));
  }
  return res;
}


x86 assembly (clang, -O0):
<solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x1,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1177 <solve+0x67>
movslq -0x14(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1030 <extended_gcd@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112a <solve+0x1a>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%eax
cmp    $0x2,%edi
jge    1135 <solve+0x25>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %edi,%r14d
add    $0x1,%r14d
mov    $0x1,%eax
mov    $0x2,%ebx
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r12
jmp    1171 <solve+0x61>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rax
xor    %edx,%edx
div    %rsi
add    $0x1,%rbx
cmp    %rbx,%r14
je     1127 <solve+0x17>
mov    %rax,%r13
imul   %rbx,%r13
mov    %rax,%rdi
mov    %ebx,%esi
mov    %r15,%rdx
mov    %r12,%rcx
call   1030 <extended_gcd@plt>
mov    %eax,%ecx
movslq %eax,%rsi
mov    %r13,%rax
or     %rsi,%rax
shr    $0x20,%rax
jne    1160 <solve+0x50>
mov    %r13d,%eax
xor    %edx,%edx
div    %ecx
jmp    1168 <solve+0x58>

LLVM IR (-O0):
define i64 @solve(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i64 1, i64* %3
store i32 2, i32* %4
br label %7
7: ; preds = %21, %1
%8 = load i32, i32* %4
%9 = load i32, i32* %2
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %24
11: ; preds = %7
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = load i64, i64* %3
%15 = mul i64 %13, %14
%16 = load i64, i64* %3
%17 = load i32, i32* %4
%18 = call i32 @extended_gcd(i64 %16, i32 %17, i32* %5, i32* %6)
%19 = sext i32 %18 to i64
%20 = udiv i64 %15, %19
store i64 %20, i64* %3
br label %21
21: ; preds = %11
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %7
24: ; preds = %7
%25 = load i64, i64* %3
ret i64 %25
}

LLVM IR (-O2):
define i64 @solve(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = icmp slt i32 %0, 2
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = add nuw i32 %0, 1
%9 = zext i32 %8 to i64
br label %12
10: ; preds = %12, %1
%11 = phi i64 [ 1, %1 ], [ %19, %12 ]
ret i64 %11
12: ; preds = %5, %12
%13 = phi i64 [ 2, %5 ], [ %20, %12 ]
%14 = phi i64 [ 1, %5 ], [ %19, %12 ]
%15 = mul i64 %14, %13
%16 = trunc i64 %13 to i32
%17 = call i32 @extended_gcd(i64 %14, i32 %16, i32* %2, i32* %3)
%18 = sext i32 %17 to i64
%19 = udiv i64 %15, %18
%20 = add nuw nsw i64 %13, 1
%21 = icmp eq i64 %20, %9
br i1 %21, label %10, label %12
}