#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 */
typedef int uint64_t;

/* Variables and functions */
int ar933x_uart_get_baud(int, unsigned int, unsigned int);
int /*<<< orphan*/ ar933x_uart_get_scale_step(int, unsigned int, unsigned int *,
                                              unsigned int *);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, ...);
void *strtol(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  uint64_t UARTCLOCK = 25000000;
  unsigned int baud = 500000;
  unsigned int scale;
  unsigned int step;
  int opt;
  while ((opt = getopt(argc, argv, "b:c:")) != -1) {
    switch (opt) {
    case 'c':
      UARTCLOCK = strtol(optarg, NULL, 0);
      break;
    case 'b':
      baud = strtol(optarg, NULL, 0);
      break;
    default:
      printf("Unknown option\n");
    }
  }
  ar933x_uart_get_scale_step(UARTCLOCK, baud, &scale, &step);
  printf("Uart Clock      :  %15ld\n"
         "Uart Baud       :  %15d\n"
         "-----------------------------------\n"
         "Uart Scale      :  %15d\n"
         "Uart Step       :  %15d\n",
         UARTCLOCK, baud, scale, step);
  int baud_real = ar933x_uart_get_baud(UARTCLOCK, scale, step);
  int baud1 = ar933x_uart_get_baud(UARTCLOCK, scale, step + 1);
  int baud2 = ar933x_uart_get_baud(UARTCLOCK, scale, step - 1);
  printf("-----------------------------------\n"
         "Uart step-1 Baud:  %15d %5d\n"
         "Uart real   Baud:  %15d %5d\n"
         "Uart step+1 Baud:  %15d %5d\n",
         baud1, baud1 - baud, baud_real, baud_real - baud, baud2, baud2 - baud);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x17d7840,-0x14(%rbp)
movl   $0x7a120,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe7e(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     1203 <main+0xb3>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x62,%eax
je     11d4 <main+0x84>
jmp    11a7 <main+0x57>
mov    -0x34(%rbp),%eax
sub    $0x63,%eax
jne    11f0 <main+0xa0>
jmp    11b8 <main+0x68>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %eax,-0x14(%rbp)
jmp    11fe <main+0xae>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %eax,-0x18(%rbp)
jmp    11fe <main+0xae>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1174 <main+0x24>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1060 <ar933x_uart_get_scale_step@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1040 <ar933x_uart_get_baud@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
call   1040 <ar933x_uart_get_baud@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
sub    $0x1,%edx
call   1040 <ar933x_uart_get_baud@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x2c(%rbp),%edx
sub    -0x18(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x28(%rbp),%r8d
sub    -0x18(%rbp),%r8d
mov    -0x30(%rbp),%r9d
mov    -0x30(%rbp),%eax
sub    -0x18(%rbp),%eax
lea    0xe0c(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x17d7840,%r15d
mov    $0x7a120,%r14d
lea    0xe7a(%rip),%r12
lea    0xf77(%rip),%r13
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1080 <getopt@plt>
cmp    $0xffffffff,%eax
je     11e4 <main+0x84>
cmp    $0x62,%eax
je     11b6 <main+0x56>
cmp    $0x63,%eax
je     11cd <main+0x6d>
mov    %r13,%rdi
call   1030 <puts@plt>
jmp    1190 <main+0x30>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %rax,%r14
jmp    1190 <main+0x30>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %rax,%r15
jmp    1190 <main+0x30>
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %r15d,%edi
mov    %r14d,%esi
call   1070 <ar933x_uart_get_scale_step@plt>
mov    0x14(%rsp),%ecx
mov    0x10(%rsp),%r8d
lea    0xdfc(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
mov    %r15d,%edi
call   1050 <ar933x_uart_get_baud@plt>
mov    %eax,%ebx
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
add    $0x1,%edx
mov    %r15d,%edi
call   1050 <ar933x_uart_get_baud@plt>
mov    %eax,%ebp
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
add    $0xffffffff,%edx
mov    %r15d,%edi
call   1050 <ar933x_uart_get_baud@plt>
mov    %ebp,%edx
sub    %r14d,%edx
mov    %ebx,%r8d
sub    %r14d,%r8d
mov    %eax,%ecx
sub    %r14d,%ecx
mov    %ecx,(%rsp)
lea    0xe21(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%ecx
mov    %eax,%r9d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"b:c:\00"
@optarg = global i32 0
@.str.1 = [16 x i8] c"Unknown option\0A\00"
@.str.2 = [134 x i8] c"Uart Clock : %15ld\0AUart Baud : %15d\0A-----------------------------------\0AUart Scale : %15d\0AUart Step : %15d\0A\00"
@.str.3 = [121 x i8] c"-----------------------------------\0AUart step-1 Baud: %15d %5d\0AUart real Baud: %15d %5d\0AUart step+1 Baud: %15d %5d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 25000000, i32* %6
store i32 500000, i32* %7
br label %14
14: ; preds = %31, %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %17, i32* %10
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %32
19: ; preds = %14
%20 = load i32, i32* %10
switch i32 %20, label %29 [
i32 99, label %21
i32 98, label %25
]
21: ; preds = %19
%22 = load i32, i32* @optarg
%23 = call i8* @strtol(i32 %22, i32* null, i32 0)
%24 = ptrtoint i8* %23 to i32
store i32 %24, i32* %6
br label %31
25: ; preds = %19
%26 = load i32, i32* @optarg
%27 = call i8* @strtol(i32 %26, i32* null, i32 0)
%28 = ptrtoint i8* %27 to i32
store i32 %28, i32* %7
br label %31
29: ; preds = %19
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %25, %21
br label %14
32: ; preds = %14
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = call i32 @ar933x_uart_get_scale_step(i32 %33, i32 %34, i32* %8, i32* %9)
%36 = load i32, i32* %6
%37 = load i32, i32* %7
%38 = load i32, i32* %8
%39 = load i32, i32* %9
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %37, i32 %38, i32 %39)
%41 = load i32, i32* %6
%42 = load i32, i32* %8
%43 = load i32, i32* %9
%44 = call i32 @ar933x_uart_get_baud(i32 %41, i32 %42, i32 %43)
store i32 %44, i32* %11
%45 = load i32, i32* %6
%46 = load i32, i32* %8
%47 = load i32, i32* %9
%48 = add i32 %47, 1
%49 = call i32 @ar933x_uart_get_baud(i32 %45, i32 %46, i32 %48)
store i32 %49, i32* %12
%50 = load i32, i32* %6
%51 = load i32, i32* %8
%52 = load i32, i32* %9
%53 = sub i32 %52, 1
%54 = call i32 @ar933x_uart_get_baud(i32 %50, i32 %51, i32 %53)
store i32 %54, i32* %13
%55 = load i32, i32* %12
%56 = load i32, i32* %12
%57 = load i32, i32* %7
%58 = sub i32 %56, %57
%59 = load i32, i32* %11
%60 = load i32, i32* %11
%61 = load i32, i32* %7
%62 = sub i32 %60, %61
%63 = load i32, i32* %13
%64 = load i32, i32* %13
%65 = load i32, i32* %7
%66 = sub i32 %64, %65
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([121 x i8], [121 x i8]* @.str.3, i64 0, i64 0), i32 %55, i32 %58, i32 %59, i32 %62, i32 %63, i32 %66)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"b:c:\00"
@optarg = global i32 0
@.str.2 = [134 x i8] c"Uart Clock : %15ld\0AUart Baud : %15d\0A-----------------------------------\0AUart Scale : %15d\0AUart Step : %15d\0A\00"
@.str.3 = [121 x i8] c"-----------------------------------\0AUart step-1 Baud: %15d %5d\0AUart real Baud: %15d %5d\0AUart step+1 Baud: %15d %5d\0A\00"
@str = [15 x i8] c"Unknown option\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
br label %7
7: ; preds = %19, %2
%8 = phi i32 [ %23, %19 ], [ 500000, %2 ]
%9 = phi i32 [ %11, %19 ], [ 25000000, %2 ]
br label %10
10: ; preds = %7, %14
%11 = phi i32 [ %9, %7 ], [ %18, %14 ]
br label %12
12: ; preds = %10, %24
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %13, label %24 [
i32 -1, label %26
i32 99, label %14
i32 98, label %19
]
14: ; preds = %12
%15 = load i32, i32* @optarg
%16 = tail call i8* @strtol(i32 %15, i32* null, i32 0)
%17 = ptrtoint i8* %16 to i64
%18 = trunc i64 %17 to i32
br label %10
19: ; preds = %12
%20 = load i32, i32* @optarg
%21 = tail call i8* @strtol(i32 %20, i32* null, i32 0)
%22 = ptrtoint i8* %21 to i64
%23 = trunc i64 %22 to i32
br label %7
24: ; preds = %12
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %12
26: ; preds = %12
%27 = call i32 @ar933x_uart_get_scale_step(i32 %11, i32 %8, i32* %3, i32* %4)
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([134 x i8], [134 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %8, i32 %28, i32 %29)
%31 = load i32, i32* %3
%32 = load i32, i32* %4
%33 = call i32 @ar933x_uart_get_baud(i32 %11, i32 %31, i32 %32)
%34 = load i32, i32* %3
%35 = load i32, i32* %4
%36 = add i32 %35, 1
%37 = call i32 @ar933x_uart_get_baud(i32 %11, i32 %34, i32 %36)
%38 = load i32, i32* %3
%39 = load i32, i32* %4
%40 = add i32 %39, -1
%41 = call i32 @ar933x_uart_get_baud(i32 %11, i32 %38, i32 %40)
%42 = sub i32 %37, %8
%43 = sub i32 %33, %8
%44 = sub i32 %41, %8
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([121 x i8], [121 x i8]* @.str.3, i64 0, i64 0), i32 %37, i32 %42, i32 %33, i32 %43, i32 %41, i32 %44)
ret i32 0
}