#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*/ printf(char *, int, int);
int sgcd(int, int);
int Sgcd(int n) {
  int cnt = 0, i, j;
  for (i = 1; i <= n; i++) {
    printf("\r%16d %16d", i, cnt);
    cnt++;
    for (j = 1; j < i; j++) {
      cnt += 2 * sgcd(i, j) + 1;
    }
  }
  return cnt;
}


x86 assembly (clang, -O0):
<Sgcd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11ab <Sgcd+0x8b>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xeae(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1198 <Sgcd+0x78>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <sgcd@plt>
shl    $0x1,%eax
add    $0x1,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1167 <Sgcd+0x47>
jmp    119d <Sgcd+0x7d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1139 <Sgcd+0x19>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Sgcd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    11a3 <Sgcd+0x83>
mov    %edi,%r15d
mov    $0x1,%r12d
xor    %r13d,%r13d
lea    0xebe(%rip),%r14
xor    %ebx,%ebx
jmp    1161 <Sgcd+0x41>
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%r12),%eax
add    $0xffffffff,%r13d
cmp    %r15d,%r12d
mov    %eax,%r12d
je     11a5 <Sgcd+0x85>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    $0x2,%r12d
jb     1150 <Sgcd+0x30>
mov    $0x1,%ebp
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %ebp,%esi
call   1030 <sgcd@plt>
lea    (%rbx,%rax,2),%ebx
add    $0x1,%ebx
lea    0x1(%r13,%rbp,1),%eax
mov    %ebp,%ecx
add    $0x1,%ecx
mov    %ecx,%ebp
cmp    $0x1,%eax
jne    1180 <Sgcd+0x60>
jmp    1150 <Sgcd+0x30>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"\0D%16d %16d\00"
define i32 @Sgcd(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 1, i32* %4
br label %6
6: ; preds = %32, %1
%7 = load i32, i32* %4
%8 = load i32, i32* %2
%9 = icmp sle i32 %7, %8
br i1 %9, label %10, label %35
10: ; preds = %6
%11 = load i32, i32* %4
%12 = load i32, i32* %3
%13 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
store i32 1, i32* %5
br label %16
16: ; preds = %28, %10
%17 = load i32, i32* %5
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %31
20: ; preds = %16
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = call i32 @sgcd(i32 %21, i32 %22)
%24 = mul nsw i32 2, %23
%25 = add nsw i32 %24, 1
%26 = load i32, i32* %3
%27 = add nsw i32 %26, %25
store i32 %27, i32* %3
br label %28
28: ; preds = %20
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %16
31: ; preds = %16
br label %32
32: ; preds = %31
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %6
35: ; preds = %6
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [11 x i8] c"\0D%16d %16d\00"
define i32 @Sgcd(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %22, label %3
3: ; preds = %1, %18
%4 = phi i32 [ %20, %18 ], [ 1, %1 ]
%5 = phi i32 [ %19, %18 ], [ 0, %1 ]
%6 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
%7 = add nsw i32 %5, 1
%8 = icmp ugt i32 %4, 1
br i1 %8, label %9, label %18
9: ; preds = %3, %9
%10 = phi i32 [ %16, %9 ], [ 1, %3 ]
%11 = phi i32 [ %15, %9 ], [ %7, %3 ]
%12 = tail call i32 @sgcd(i32 %4, i32 %10)
%13 = shl nsw i32 %12, 1
%14 = add i32 %11, 1
%15 = add i32 %14, %13
%16 = add nuw nsw i32 %10, 1
%17 = icmp eq i32 %16, %4
br i1 %17, label %18, label %9
18: ; preds = %9, %3
%19 = phi i32 [ %7, %3 ], [ %15, %9 ]
%20 = add nuw i32 %4, 1
%21 = icmp eq i32 %4, %0
br i1 %21, label %22, label %3
22: ; preds = %18, %1
%23 = phi i32 [ 0, %1 ], [ %19, %18 ]
ret i32 %23
}