#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 expon(int, int, int);
int num_weak(int n) {
  int witnesses = 0;
  for (int a = 2; a < n - 1; a++) {
    if (expon(a, n - 1, n) == 1) {
      witnesses++;
    }
  }
  return witnesses;
}


x86 assembly (clang, -O0):
<num_weak>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1170 <num_weak+0x60>
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%esi
sub    $0x1,%esi
mov    -0x4(%rbp),%edx
call   1030 <expon@plt>
cmp    $0x1,%eax
jne    115d <num_weak+0x4d>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1162 <num_weak+0x52>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1129 <num_weak+0x19>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_weak>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %ebp,%ebp
cmp    $0x4,%edi
jl     116a <num_weak+0x5a>
mov    %edi,%r15d
lea    -0x1(%r15),%r14d
mov    %edi,%r12d
neg    %r12d
xor    %ebp,%ebp
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %r14d,%esi
mov    %r15d,%edx
call   1030 <expon@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
sete   %cl
add    %ecx,%ebp
lea    (%r12,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0xffffffff,%eax
jne    1140 <num_weak+0x30>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @num_weak(i32 %0) {
%2 = add i32 %0, -1
%3 = icmp sgt i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %6, %1
%5 = phi i32 [ 0, %1 ], [ %12, %6 ]
ret i32 %5
6: ; preds = %1, %6
%7 = phi i32 [ %13, %6 ], [ 2, %1 ]
%8 = phi i32 [ %12, %6 ], [ 0, %1 ]
%9 = tail call i32 @expon(i32 %7, i32 %2, i32 %0)
%10 = icmp eq i32 %9, 1
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %8, %11
%13 = add nuw nsw i32 %7, 1
%14 = icmp eq i32 %13, %2
br i1 %14, label %4, label %6
}