#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*/ FNM_PATHNAME;
unsigned int abs(double);
double atof(char *);
int /*<<< orphan*/ compute_clock(unsigned int, double, double, int, int,
                                 unsigned int *, unsigned int *, unsigned int *,
                                 unsigned int *);
int /*<<< orphan*/ fnmatch(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
unsigned int probe_chip();
int set_clock(unsigned int, unsigned int, unsigned int, unsigned int,
              unsigned int, unsigned int, unsigned int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  double target;
  double Fref = 14318180;
  unsigned int M, N, P, PSN, ChipType, ClockType, progclock;
  switch (argc) {
  case 2:
    progclock = 2;
    target = atof(argv[1]);
    break;
  case 3:
    progclock = abs(atof(argv[1]));
    target = atof(argv[2]);
    break;
  default:
    fprintf(stderr, "usage: %s [-0|-1|-2] freq\n", argv[0]);
    return 1;
  }
  ClockType = 0;
  if (!fnmatch("*memClock", argv[0], FNM_PATHNAME)) {
    ClockType = 1;
  }
  ChipType = probe_chip();
  if (!ChipType) {
    return 1;
  }
  if (!ChipType & 0x10) {
    fprintf(stderr, "No programmable Clock!\n");
    return 1;
  }
  if (ChipType & 0x20) {
    if (!compute_clock(ChipType, target, Fref, 63, 127, &M, &N, &P, &PSN)) {
      return set_clock(ChipType, ClockType, progclock, M, N, P, PSN);
    } else {
      return 1;
    }
  } else {
    if (!compute_clock(ChipType, target, Fref, 127, 127, &M, &N, &P, &PSN)) {
      return set_clock(ChipType, ClockType, progclock, M, N, P, PSN);
    } else {
      return 1;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0x416b4f4c80000000,%rax
4f 6b 41
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x2,%eax
je     11b9 <main+0x49>
jmp    11a8 <main+0x38>
mov    -0x40(%rbp),%eax
sub    $0x3,%eax
je     11d7 <main+0x67>
jmp    1203 <main+0x93>
movl   $0x2,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    122d <main+0xbd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atof@plt>
call   1030 <abs@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    122d <main+0xbd>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    139c <main+0x22c>
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
lea    0xdd0(%rip),%rdi
call   1050 <fnmatch@plt>
cmp    $0x0,%eax
jne    1260 <main+0xf0>
movl   $0x1,-0x38(%rbp)
mov    $0x0,%al
call   1060 <probe_chip@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    1280 <main+0x110>
movl   $0x1,-0x4(%rbp)
jmp    139c <main+0x22c>
cmpl   $0x0,-0x34(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     12bd <main+0x14d>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
lea    0xd7b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    139c <main+0x22c>
mov    -0x34(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     1338 <main+0x1c8>
mov    -0x34(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    $0x3f,%esi
mov    $0x7f,%edx
lea    -0x24(%rbp),%rcx
lea    -0x28(%rbp),%r8
lea    -0x2c(%rbp),%r9
lea    -0x30(%rbp),%rax
mov    %rax,(%rsp)
call   1090 <compute_clock@plt>
cmp    $0x0,%eax
jne    132c <main+0x1bc>
mov    -0x34(%rbp),%edi
mov    -0x38(%rbp),%esi
mov    -0x3c(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%eax
mov    %eax,(%rsp)
call   1080 <set_clock@plt>
mov    %eax,-0x4(%rbp)
jmp    139c <main+0x22c>
movl   $0x1,-0x4(%rbp)
jmp    139c <main+0x22c>
mov    -0x34(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    $0x7f,%edx
lea    -0x24(%rbp),%rcx
lea    -0x28(%rbp),%r8
lea    -0x2c(%rbp),%r9
lea    -0x30(%rbp),%rax
mov    %edx,%esi
mov    %rax,(%rsp)
call   1090 <compute_clock@plt>
cmp    $0x0,%eax
jne    1395 <main+0x225>
mov    -0x34(%rbp),%edi
mov    -0x38(%rbp),%esi
mov    -0x3c(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%eax
mov    %eax,(%rsp)
call   1080 <set_clock@plt>
mov    %eax,-0x4(%rbp)
jmp    139c <main+0x22c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %edi,%r15d
cmp    $0x2,%edi
je     11a9 <main+0x39>
cmp    $0x3,%r15d
jne    122c <main+0xbc>
mov    0x8(%rbx),%rdi
call   1040 <atof@plt>
call   1030 <abs@plt>
mov    %eax,%r15d
mov    $0x2,%eax
jmp    11ae <main+0x3e>
mov    $0x1,%eax
mov    (%rbx,%rax,8),%rdi
call   1040 <atof@plt>
movsd  %xmm0,0x18(%rsp)
mov    (%rbx),%rsi
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
lea    0xe53(%rip),%rdi
call   1050 <fnmatch@plt>
xor    %r14d,%r14d
test   %eax,%eax
sete   %bl
xor    %eax,%eax
call   1060 <probe_chip@plt>
mov    $0x1,%r12d
test   %eax,%eax
je     12a9 <main+0x139>
mov    %eax,%ebp
mov    %bl,%r14b
lea    0x8(%rsp),%rax
test   $0x20,%bpl
jne    124e <main+0xde>
mov    %rax,(%rsp)
movsd  0xdf2(%rip),%xmm1
lea    0x14(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebp,%edi
movsd  0x18(%rsp),%xmm0
mov    $0x7f,%esi
jmp    1276 <main+0x106>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdc9(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%r12d
jmp    12a9 <main+0x139>
mov    %rax,(%rsp)
movsd  0xda6(%rip),%xmm1
lea    0x14(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebp,%edi
movsd  0x18(%rsp),%xmm0
mov    $0x3f,%esi
mov    $0x7f,%edx
call   1090 <compute_clock@plt>
test   %eax,%eax
jne    12a9 <main+0x139>
mov    0x14(%rsp),%ecx
mov    0x10(%rsp),%r8d
mov    0xc(%rsp),%r9d
mov    0x8(%rsp),%eax
mov    %eax,(%rsp)
mov    %ebp,%edi
mov    %r14d,%esi
mov    %r15d,%edx
call   1080 <set_clock@plt>
mov    %eax,%r12d
mov    %r12d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"usage: %s [-0|-1|-2] freq\0A\00"
@.str.1 = [10 x i8] c"*memClock\00"
@FNM_PATHNAME = global i32 0
@.str.2 = [24 x i8] c"No programmable Clock!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0x416B4F4C80000000, double* %7
%15 = load i32, i32* %4
switch i32 %15, label %31 [
i32 2, label %16
i32 3, label %21
]
16: ; preds = %2
store i32 2, i32* %14
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call double @atof(i8* %19)
store double %20, double* %6
br label %37
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call double @atof(i8* %24)
%26 = call i32 @abs(double %25)
store i32 %26, i32* %14
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call double @atof(i8* %29)
store double %30, double* %6
br label %37
31: ; preds = %2
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %35)
store i32 1, i32* %3
br label %96
37: ; preds = %21, %16
store i32 0, i32* %13
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 0
%40 = load i8*, i8** %39
%41 = load i32, i32* @FNM_PATHNAME
%42 = call i32 @fnmatch(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %40, i32 %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %37
store i32 1, i32* %13
br label %45
45: ; preds = %44, %37
%46 = call i32 (...) @probe_chip()
store i32 %46, i32* %12
%47 = load i32, i32* %12
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %45
store i32 1, i32* %3
br label %96
50: ; preds = %45
%51 = load i32, i32* %12
%52 = icmp ne i32 %51, 0
%53 = xor i1 %52, true
%54 = zext i1 %53 to i32
%55 = and i32 %54, 16
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %50
%58 = load i32, i32* @stderr
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %96
60: ; preds = %50
%61 = load i32, i32* %12
%62 = and i32 %61, 32
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %80
64: ; preds = %60
%65 = load i32, i32* %12
%66 = load double, double* %6
%67 = load double, double* %7
%68 = call i32 @compute_clock(i32 %65, double %66, double %67, i32 63, i32 127, i32* %8, i32* %9, i32* %10, i32* %11)
%69 = icmp ne i32 %68, 0
br i1 %69, label %79, label %70
70: ; preds = %64
%71 = load i32, i32* %12
%72 = load i32, i32* %13
%73 = load i32, i32* %14
%74 = load i32, i32* %8
%75 = load i32, i32* %9
%76 = load i32, i32* %10
%77 = load i32, i32* %11
%78 = call i32 @set_clock(i32 %71, i32 %72, i32 %73, i32 %74, i32 %75, i32 %76, i32 %77)
store i32 %78, i32* %3
br label %96
79: ; preds = %64
store i32 1, i32* %3
br label %96
80: ; preds = %60
%81 = load i32, i32* %12
%82 = load double, double* %6
%83 = load double, double* %7
%84 = call i32 @compute_clock(i32 %81, double %82, double %83, i32 127, i32 127, i32* %8, i32* %9, i32* %10, i32* %11)
%85 = icmp ne i32 %84, 0
br i1 %85, label %95, label %86
86: ; preds = %80
%87 = load i32, i32* %12
%88 = load i32, i32* %13
%89 = load i32, i32* %14
%90 = load i32, i32* %8
%91 = load i32, i32* %9
%92 = load i32, i32* %10
%93 = load i32, i32* %11
%94 = call i32 @set_clock(i32 %87, i32 %88, i32 %89, i32 %90, i32 %91, i32 %92, i32 %93)
store i32 %94, i32* %3
br label %96
95: ; preds = %80
store i32 1, i32* %3
br label %96
96: ; preds = %95, %86, %79, %70, %57, %49, %31
%97 = load i32, i32* %3
ret i32 %97
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"usage: %s [-0|-1|-2] freq\0A\00"
@.str.1 = [10 x i8] c"*memClock\00"
@FNM_PATHNAME = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
switch i32 %0, label %16 [
i32 2, label %20
i32 3, label %11
]
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call double @atof(i8* %13)
%15 = tail call i32 @abs(double %14)
br label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %1
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %54
20: ; preds = %2, %11
%21 = phi i64 [ 2, %11 ], [ 1, %2 ]
%22 = phi i32 [ %15, %11 ], [ %0, %2 ]
%23 = getelementptr inbounds i8*, i8** %1, i64 %21
%24 = load i8*, i8** %23
%25 = tail call double @atof(i8* %24)
%26 = load i8*, i8** %1
%27 = load i32, i32* @FNM_PATHNAME
%28 = tail call i32 @fnmatch(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %27)
%29 = icmp eq i32 %28, 0
%30 = zext i1 %29 to i32
%31 = tail call i32 (...) @probe_chip()
%32 = icmp eq i32 %31, 0
br i1 %32, label %54, label %33
33: ; preds = %20
%34 = and i32 %31, 32
%35 = icmp eq i32 %34, 0
br i1 %35, label %45, label %36
36: ; preds = %33
%37 = call i32 @compute_clock(i32 %31, double %25, double 0x416B4F4C80000000, i32 63, i32 127, i32* %3, i32* %4, i32* %5, i32* %6)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %54
39: ; preds = %36
%40 = load i32, i32* %3
%41 = load i32, i32* %4
%42 = load i32, i32* %5
%43 = load i32, i32* %6
%44 = call i32 @set_clock(i32 %31, i32 %30, i32 %22, i32 %40, i32 %41, i32 %42, i32 %43)
br label %54
45: ; preds = %33
%46 = call i32 @compute_clock(i32 %31, double %25, double 0x416B4F4C80000000, i32 127, i32 127, i32* %3, i32* %4, i32* %5, i32* %6)
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %54
48: ; preds = %45
%49 = load i32, i32* %3
%50 = load i32, i32* %4
%51 = load i32, i32* %5
%52 = load i32, i32* %6
%53 = call i32 @set_clock(i32 %31, i32 %30, i32 %22, i32 %49, i32 %50, i32 %51, i32 %52)
br label %54
54: ; preds = %45, %36, %20, %48, %39, %16
%55 = phi i32 [ 1, %16 ], [ %44, %39 ], [ %53, %48 ], [ 1, %20 ], [ 1, %36 ], [ 1, %45 ]
ret i32 %55
}