#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ print_cycles_long(unsigned int);
int /*<<< orphan*/ print_cycles_short(unsigned int);
int /*<<< orphan*/ print_gauss_map(unsigned int);
int /*<<< orphan*/ print_quotient_rest(unsigned int);
int sscanf(char *, char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  unsigned int n;
  char c;
  if ((argc != 3) || (sscanf(argv[1], "%c", &c) != 1) ||
      ((c != 'g') && (c != 's') && (c != 'l') && (c != 'q')) ||
      (sscanf(argv[2], "%ld", &n) != 1)) {
    fprintf(stderr, "usage: gauss_map C N\n");
    fprintf(stderr, "   C: might be 'g' (gauss map), 's' (cycles short) or 'l' "
                    "(cycles long)\n");
    fprintf(stderr, "   N: a positive integer\n");
    exit(1);
  }
  if (n > ((unsigned long)1) << (4 * sizeof(unsigned long))) {
    fprintf(stderr, "N=%ld is too large, the maximum value allowed is %ld\n", n,
            ((unsigned long)1) << (4 * sizeof(unsigned long)));
    exit(1);
  }
  if (c == 'g')
    print_gauss_map(n);
  if (c == 's')
    print_cycles_short(n);
  if (c == 'l')
    print_cycles_long(n);
  if (c == 'q')
    print_quotient_rest(n);
  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)
jne    120a <main+0x9a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe61(%rip),%rsi
lea    -0x15(%rbp),%rdx
mov    $0x0,%al
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    120a <main+0x9a>
movsbl -0x15(%rbp),%eax
cmp    $0x67,%eax
je     11e7 <main+0x77>
movsbl -0x15(%rbp),%eax
cmp    $0x73,%eax
je     11e7 <main+0x77>
movsbl -0x15(%rbp),%eax
cmp    $0x6c,%eax
je     11e7 <main+0x77>
movsbl -0x15(%rbp),%eax
cmp    $0x71,%eax
jne    120a <main+0x9a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe0d(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1070 <sscanf@plt>
cmp    $0x1,%eax
je     1259 <main+0xe9>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%eax
movabs $0x100000000,%rcx
cmp    %rcx,%rax
jbe    129d <main+0x12d>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xdfe(%rip),%rsi
movabs $0x100000000,%rcx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movsbl -0x15(%rbp),%eax
cmp    $0x67,%eax
jne    12b2 <main+0x142>
mov    -0x14(%rbp),%edi
call   1030 <print_gauss_map@plt>
movsbl -0x15(%rbp),%eax
cmp    $0x73,%eax
jne    12c7 <main+0x157>
mov    -0x14(%rbp),%edi
call   1080 <print_cycles_short@plt>
movsbl -0x15(%rbp),%eax
cmp    $0x6c,%eax
jne    12dc <main+0x16c>
mov    -0x14(%rbp),%edi
call   1040 <print_cycles_long@plt>
movsbl -0x15(%rbp),%eax
cmp    $0x71,%eax
jne    12f1 <main+0x181>
mov    -0x14(%rbp),%edi
call   1050 <print_quotient_rest@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    1233 <main+0xc3>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe74(%rip),%rsi
lea    0xb(%rsp),%rdx
xor    %eax,%eax
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    1233 <main+0xc3>
mov    0xb(%rsp),%al
add    $0x99,%al
cmp    $0xc,%al
ja     1233 <main+0xc3>
movzbl %al,%eax
mov    $0x1421,%ecx
bt     %rax,%rcx
jae    1233 <main+0xc3>
mov    0x10(%rbx),%rdi
lea    0xe3b(%rip),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    1233 <main+0xc3>
mov    0xb(%rsp),%al
cmp    $0x67,%al
je     11fe <main+0x8e>
cmp    $0x73,%al
je     120f <main+0x9f>
cmp    $0x6c,%al
je     1220 <main+0xb0>
cmp    $0x71,%al
jne    11f6 <main+0x86>
mov    0xc(%rsp),%edi
call   1050 <print_quotient_rest@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0xc(%rsp),%edi
call   1030 <print_gauss_map@plt>
mov    0xb(%rsp),%al
cmp    $0x73,%al
jne    11e5 <main+0x75>
mov    0xc(%rsp),%edi
call   1080 <print_cycles_short@plt>
mov    0xb(%rsp),%al
cmp    $0x6c,%al
jne    11e9 <main+0x79>
mov    0xc(%rsp),%edi
call   1040 <print_cycles_long@plt>
mov    0xb(%rsp),%al
cmp    $0x71,%al
je     11ed <main+0x7d>
jmp    11f6 <main+0x86>
mov    0x2da6(%rip),%rbx
mov    (%rbx),%edi
lea    0xdc4(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdca(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe03(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [4 x i8] c"%ld\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"usage: gauss_map C N\0A\00"
@.str.3 = [73 x i8] c" C: might be 'g' (gauss map), 's' (cycles short) or 'l' (cycles long)\0A\00"
@.str.4 = [26 x i8] c" N: a positive integer\0A\00"
@.str.5 = [54 x i8] c"N=%ld is too large, the maximum value allowed is %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
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 %38, label %10
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 (i8*, i8*, ...) @sscanf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
%15 = icmp ne i32 %14, 1
br i1 %15, label %38, label %16
16: ; preds = %10
%17 = load i8, i8* %7
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 103
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = load i8, i8* %7
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 115
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i8, i8* %7
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 108
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i8, i8* %7
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 113
br i1 %31, label %38, label %32
32: ; preds = %28, %24, %20, %16
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 (i8*, i8*, ...) @sscanf(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%37 = icmp ne i32 %36, 1
br i1 %37, label %38, label %46
38: ; preds = %32, %28, %10, %2
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %32
%47 = load i32, i32* %6
%48 = zext i32 %47 to i64
%49 = icmp ugt i64 %48, 4294967296
br i1 %49, label %50, label %55
50: ; preds = %46
%51 = load i32, i32* @stderr
%52 = load i32, i32* %6
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i32 %52, i64 4294967296)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %46
%56 = load i8, i8* %7
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 103
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = load i32, i32* %6
%61 = call i32 @print_gauss_map(i32 %60)
br label %62
62: ; preds = %59, %55
%63 = load i8, i8* %7
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 115
br i1 %65, label %66, label %69
66: ; preds = %62
%67 = load i32, i32* %6
%68 = call i32 @print_cycles_short(i32 %67)
br label %69
69: ; preds = %66, %62
%70 = load i8, i8* %7
%71 = sext i8 %70 to i32
%72 = icmp eq i32 %71, 108
br i1 %72, label %73, label %76
73: ; preds = %69
%74 = load i32, i32* %6
%75 = call i32 @print_cycles_long(i32 %74)
br label %76
76: ; preds = %73, %69
%77 = load i8, i8* %7
%78 = sext i8 %77 to i32
%79 = icmp eq i32 %78, 113
br i1 %79, label %80, label %83
80: ; preds = %76
%81 = load i32, i32* %6
%82 = call i32 @print_quotient_rest(i32 %81)
br label %83
83: ; preds = %80, %76
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@.str.1 = [4 x i8] c"%ld\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"usage: gauss_map C N\0A\00"
@.str.3 = [73 x i8] c" C: might be 'g' (gauss map), 's' (cycles short) or 'l' (cycles long)\0A\00"
@.str.4 = [26 x i8] c" N: a positive integer\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i8
%5 = bitcast i32* %3 to i8*
%6 = icmp eq i32 %0, 3
br i1 %6, label %7, label %19
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = call i32 (i8*, i8*, ...) @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %19
12: ; preds = %7
%13 = load i8, i8* %4
switch i8 %13, label %19 [
i8 115, label %14
i8 113, label %14
i8 108, label %14
i8 103, label %14
]
14: ; preds = %12, %12, %12, %12
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = call i32 (i8*, i8*, ...) @sscanf(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%18 = icmp eq i32 %17, 1
br i1 %18, label %27, label %19
19: ; preds = %12, %14, %7, %2
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %14
%28 = load i8, i8* %4
%29 = icmp eq i8 %28, 103
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32, i32* %3
%32 = call i32 @print_gauss_map(i32 %31)
%33 = load i8, i8* %4
br label %34
34: ; preds = %30, %27
%35 = phi i8 [ %33, %30 ], [ %28, %27 ]
%36 = icmp eq i8 %35, 115
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i32, i32* %3
%39 = call i32 @print_cycles_short(i32 %38)
%40 = load i8, i8* %4
br label %41
41: ; preds = %37, %34
%42 = phi i8 [ %40, %37 ], [ %35, %34 ]
%43 = icmp eq i8 %42, 108
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i32, i32* %3
%46 = call i32 @print_cycles_long(i32 %45)
%47 = load i8, i8* %4
br label %48
48: ; preds = %44, %41
%49 = phi i8 [ %47, %44 ], [ %42, %41 ]
%50 = icmp eq i8 %49, 113
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i32, i32* %3
%53 = call i32 @print_quotient_rest(i32 %52)
br label %54
54: ; preds = %51, %48
ret i32 0
}