#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ generate_mod(int, int);
int /*<<< orphan*/ generate_sq_res_0x100(int);
int /*<<< orphan*/ print(int, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int limb_bits, nail_bits;
  if (argc != 3) {
    fprintf(stderr, "Usage: gen-psqr <limbbits> <nailbits>\n");
    exit(1);
  }
  limb_bits = atoi(argv[1]);
  nail_bits = atoi(argv[2]);
  if (limb_bits <= 0 || nail_bits < 0 || nail_bits >= limb_bits) {
    fprintf(stderr, "Invalid limb/nail bits: %d %d\n", limb_bits, nail_bits);
    exit(1);
  }
  generate_sq_res_0x100(limb_bits);
  generate_mod(limb_bits, nail_bits);
  print(limb_bits, nail_bits);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a1 <main+0x41>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11e1 <main+0x81>
cmpl   $0x0,-0x18(%rbp)
jl     11e1 <main+0x81>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1208 <main+0xa8>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <generate_sq_res_0x100@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1060 <generate_mod@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <print@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    11af <main+0x4f>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
mov    0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
test   %ebx,%ebx
jle    11d0 <main+0x70>
test   %ebp,%ebp
js     11d0 <main+0x70>
cmp    %ebx,%ebp
jge    11d0 <main+0x70>
mov    %ebx,%edi
call   1050 <generate_sq_res_0x100@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1060 <generate_mod@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <print@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"Usage: gen-psqr <limbbits> <nailbits>\0A\00"
@.str.1 = [31 x i8] c"Invalid limb/nail bits: %d %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %7
%23 = load i32, i32* %6
%24 = icmp sle i32 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %14
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = load i32, i32* %7
%30 = load i32, i32* %6
%31 = icmp sge i32 %29, %30
br i1 %31, label %32, label %38
32: ; preds = %28, %25, %14
%33 = load i32, i32* @stderr
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %28
%39 = load i32, i32* %6
%40 = call i32 @generate_sq_res_0x100(i32 %39)
%41 = load i32, i32* %6
%42 = load i32, i32* %7
%43 = call i32 @generate_mod(i32 %41, i32 %42)
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = call i32 @print(i32 %44, i32 %45)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"Usage: gen-psqr <limbbits> <nailbits>\0A\00"
@.str.1 = [31 x i8] c"Invalid limb/nail bits: %d %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = icmp sgt i32 %11, 0
%16 = icmp sgt i32 %14, -1
%17 = select i1 %15, i1 %16, i1 false
%18 = icmp slt i32 %14, %11
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %24, label %20
20: ; preds = %8
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %14)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %8
%25 = tail call i32 @generate_sq_res_0x100(i32 %11)
%26 = tail call i32 @generate_mod(i32 %11, i32 %14)
%27 = tail call i32 @print(i32 %11, i32 %14)
ret i32 0
}