#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 uint32_t;

/* Variables and functions */
int bl_uart_read_reg(int);
int /*<<< orphan*/ bl_uart_write_reg(int, int);
void bl_uart_init(uint32_t uart_clk) {
  uint32_t integer, remainder, fraction;
  uint32_t dll_dlm, sample_count, sample_point, temp_lcr;
  uint32_t fraction_L_mapping[] = {0x00, 0x00, 0x20, 0x90, 0xa8,
                                   0x54, 0x6c, 0xba, 0xf6, 0xfe};
  uint32_t fraction_M_mapping[] = {0x00, 0x00, 0x00, 0x00, 0x00,
                                   0x01, 0x01, 0x01, 0x01, 0x01};
  *(volatile uint32_t *)0xA2020C08 = 0x000000ff;
  *(volatile uint32_t *)0xA2020C04 = 0x00000033;
  *(volatile uint32_t *)0xA2010324 |= 0x00008000;
  integer = uart_clk / (115200 * 256);
  remainder = ((uart_clk * 10) / (115200 * 256)) % 10;
  if ((remainder != 0) || (integer == 0)) {
    integer += 1;
  }
  dll_dlm = integer;
  sample_count = uart_clk / (115200 * dll_dlm);
  while (sample_count > 256) {
    dll_dlm++;
    sample_count = uart_clk / (115200 * dll_dlm);
  }
  fraction = ((uart_clk * 10) / (115200 * dll_dlm)) % 10;
  sample_count -= 1;
  sample_point = (sample_count - 1) >> 1;
  bl_uart_write_reg((0xa00f0000 + 0x24), 0x0003);
  temp_lcr = bl_uart_read_reg((0xa00f0000 + 0xc));
  bl_uart_write_reg((0xa00f0000 + 0xc), temp_lcr | 0x0080);
  bl_uart_write_reg((0xa00f0000 + 0x0), dll_dlm & 0x00ff);
  bl_uart_write_reg((0xa00f0000 + 0x4), (dll_dlm >> 8) & 0x00ff);
  bl_uart_write_reg((0xa00f0000 + 0xc), temp_lcr);
  bl_uart_write_reg((0xa00f0000 + 0x28), sample_count);
  bl_uart_write_reg((0xa00f0000 + 0x2c), sample_point);
  bl_uart_write_reg((0xa00f0000 + 0x54), fraction_L_mapping[fraction]);
  bl_uart_write_reg((0xa00f0000 + 0x58), fraction_M_mapping[fraction]);
  bl_uart_write_reg((0xa00f0000 + 0xc), 0x0003 | 0x0000 | 0x0000);
  bl_uart_write_reg((0xa00f0000 + 0x8), (0x0010 | 0x0080 | 0x0007));
  bl_uart_write_reg((0xa00f0000 + 0x4), 0x0000);
}


x86 assembly (clang, -O0):
<bl_uart_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xea7(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
movl   $0x1,-0x6c(%rbp)
movl   $0x1,-0x68(%rbp)
movl   $0x1,-0x64(%rbp)
movl   $0x1,-0x60(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    $0xa2020c08,%eax
movl   $0xff,(%rax)
mov    $0xa2020c04,%eax
movl   $0x33,(%rax)
mov    $0xa2010324,%eax
mov    (%rax),%ecx
or     $0x8000,%ecx
mov    $0xa2010324,%eax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
mov    $0x1c20000,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
imul   $0xa,-0x4(%rbp),%eax
mov    $0x1c20000,%ecx
cltd
idiv   %ecx
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11f9 <bl_uart_init+0xb9>
cmpl   $0x0,-0x8(%rbp)
jne    1202 <bl_uart_init+0xc2>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
imul   $0x1c200,-0x14(%rbp),%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
cmpl   $0x100,-0x18(%rbp)
jle    1243 <bl_uart_init+0x103>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
imul   $0x1c200,-0x14(%rbp),%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
jmp    1218 <bl_uart_init+0xd8>
imul   $0xa,-0x4(%rbp),%eax
imul   $0x1c200,-0x14(%rbp),%ecx
cltd
idiv   %ecx
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
sar    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    $0xa00f0024,%edi
mov    $0x3,%esi
call   1060 <bl_uart_write_reg@plt>
mov    $0xa00f000c,%edi
call   1030 <bl_uart_read_reg@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
or     $0x80,%esi
mov    $0xa00f000c,%edi
call   1060 <bl_uart_write_reg@plt>
mov    -0x14(%rbp),%esi
and    $0xff,%esi
mov    $0xa00f0000,%edi
call   1060 <bl_uart_write_reg@plt>
mov    -0x14(%rbp),%esi
sar    $0x8,%esi
and    $0xff,%esi
mov    $0xa00f0004,%edi
call   1060 <bl_uart_write_reg@plt>
mov    -0x20(%rbp),%esi
mov    $0xa00f000c,%edi
call   1060 <bl_uart_write_reg@plt>
mov    -0x18(%rbp),%esi
mov    $0xa00f0028,%edi
call   1060 <bl_uart_write_reg@plt>
mov    -0x1c(%rbp),%esi
mov    $0xa00f002c,%edi
call   1060 <bl_uart_write_reg@plt>
movslq -0x10(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%esi
mov    $0xa00f0054,%edi
call   1060 <bl_uart_write_reg@plt>
movslq -0x10(%rbp),%rax
mov    -0x80(%rbp,%rax,4),%esi
mov    $0xa00f0058,%edi
call   1060 <bl_uart_write_reg@plt>
mov    $0xa00f000c,%edi
mov    $0x3,%esi
call   1060 <bl_uart_write_reg@plt>
mov    $0xa00f0008,%edi
mov    $0x97,%esi
call   1060 <bl_uart_write_reg@plt>
mov    $0xa00f0004,%edi
xor    %esi,%esi
call   1060 <bl_uart_write_reg@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bl_uart_init>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movaps 0xec1(%rip),%xmm0
movups %xmm0,0x14(%rsp)
movl   $0x1,0x24(%rsp)
mov    $0xa2010324,%eax
movl   $0xff,0x108e4(%rax)
movl   $0x33,0x108e0(%rax)
orl    $0x8000,(%rax)
movslq %edi,%rcx
imul   $0xffffffff91a2b3c5,%rcx,%rax
shr    $0x20,%rax
add    %edi,%eax
imul   $0xffffffffb60b60b7,%rcx,%rdx
shr    $0x20,%rdx
add    %edi,%edx
mov    %edx,%esi
shr    $0x1f,%esi
sar    $0x15,%edx
add    %esi,%edx
mov    %eax,%esi
shr    $0x1f,%esi
sar    $0x18,%eax
imul   $0xffffcccd,%edx,%edx
add    $0x1998,%edx
ror    %dx
add    %esi,%eax
movzwl %dx,%edx
cmp    $0x1999,%edx
setae  %dl
add    $0x1c1ffff,%ecx
cmp    $0x383ffff,%ecx
setb   %cl
or     %dl,%cl
movzbl %cl,%ecx
lea    (%rcx,%rax,1),%ebx
add    $0xffffffff,%ebx
add    %ecx,%eax
imul   $0x1c200,%eax,%ecx
nopl   0x0(%rax)
mov    %edi,%eax
cltd
idiv   %ecx
add    $0x1,%ebx
add    $0x1c200,%ecx
cmp    $0x100,%eax
jg     11e0 <bl_uart_init+0xc0>
mov    %eax,%ebp
add    %edi,%edi
lea    (%rdi,%rdi,4),%eax
add    $0xfffe3e00,%ecx
cltd
idiv   %ecx
movslq %eax,%r12
imul   $0x66666667,%r12,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r12d
lea    -0x1(%rbp),%r14d
add    $0xfffffffe,%ebp
sar    %ebp
mov    $0xa00f0024,%edi
mov    $0x3,%esi
call   1040 <bl_uart_write_reg@plt>
mov    $0xa00f000c,%edi
call   1030 <bl_uart_read_reg@plt>
mov    %eax,%r15d
mov    %eax,%esi
or     $0x80,%esi
mov    $0xa00f000c,%edi
call   1040 <bl_uart_write_reg@plt>
movzbl %bl,%esi
mov    $0xa00f0000,%edi
call   1040 <bl_uart_write_reg@plt>
movzbl %bh,%esi
mov    $0xa00f0004,%edi
call   1040 <bl_uart_write_reg@plt>
mov    $0xa00f000c,%edi
mov    %r15d,%esi
call   1040 <bl_uart_write_reg@plt>
mov    $0xa00f0028,%edi
mov    %r14d,%esi
call   1040 <bl_uart_write_reg@plt>
mov    $0xa00f002c,%edi
mov    %ebp,%esi
call   1040 <bl_uart_write_reg@plt>
movslq %r12d,%rbx
lea    0xd6b(%rip),%rax
mov    (%rax,%rbx,4),%esi
mov    $0xa00f0054,%edi
call   1040 <bl_uart_write_reg@plt>
mov    (%rsp,%rbx,4),%esi
mov    $0xa00f0058,%edi
call   1040 <bl_uart_write_reg@plt>
mov    $0xa00f000c,%edi
mov    $0x3,%esi
call   1040 <bl_uart_write_reg@plt>
mov    $0xa00f0008,%edi
mov    $0x97,%esi
call   1040 <bl_uart_write_reg@plt>
mov    $0xa00f0004,%edi
xor    %esi,%esi
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <bl_uart_write_reg@plt>

LLVM IR (-O0):
@__const.bl_uart_init.fraction_L_mapping = [10 x i32] [i32 0, i32 0, i32 32, i32 144, i32 168, i32 84, i32 108, i32 186, i32 246, i32 254]
define void @bl_uart_init(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [10 x i32]
%11 = alloca [10 x i32]
store i32 %0, i32* %2
%12 = bitcast [10 x i32]* %10 to i8*
%13 = bitcast [10 x i32]* %11 to i8*
%14 = bitcast i8* %13 to [10 x i32]*
%15 = getelementptr inbounds [10 x i32], [10 x i32]* %14, i32 0, i32 5
store i32 1, i32* %15
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %14, i32 0, i32 6
store i32 1, i32* %16
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %14, i32 0, i32 7
store i32 1, i32* %17
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %14, i32 0, i32 8
store i32 1, i32* %18
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %14, i32 0, i32 9
store i32 1, i32* %19
store volatile i32 255, i32* inttoptr (i64 2718043144 to i32*)
store volatile i32 51, i32* inttoptr (i64 2718043140 to i32*)
%20 = load volatile i32, i32* inttoptr (i64 2717975332 to i32*)
%21 = or i32 %20, 32768
store volatile i32 %21, i32* inttoptr (i64 2717975332 to i32*)
%22 = load i32, i32* %2
%23 = sdiv i32 %22, 29491200
store i32 %23, i32* %3
%24 = load i32, i32* %2
%25 = mul nsw i32 %24, 10
%26 = sdiv i32 %25, 29491200
%27 = srem i32 %26, 10
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %1
%31 = load i32, i32* %3
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30, %1
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %36
36: ; preds = %33, %30
%37 = load i32, i32* %3
store i32 %37, i32* %6
%38 = load i32, i32* %2
%39 = load i32, i32* %6
%40 = mul nsw i32 115200, %39
%41 = sdiv i32 %38, %40
store i32 %41, i32* %7
br label %42
42: ; preds = %45, %36
%43 = load i32, i32* %7
%44 = icmp sgt i32 %43, 256
br i1 %44, label %45, label %52
45: ; preds = %42
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
%48 = load i32, i32* %2
%49 = load i32, i32* %6
%50 = mul nsw i32 115200, %49
%51 = sdiv i32 %48, %50
store i32 %51, i32* %7
br label %42
52: ; preds = %42
%53 = load i32, i32* %2
%54 = mul nsw i32 %53, 10
%55 = load i32, i32* %6
%56 = mul nsw i32 115200, %55
%57 = sdiv i32 %54, %56
%58 = srem i32 %57, 10
store i32 %58, i32* %5
%59 = load i32, i32* %7
%60 = sub nsw i32 %59, 1
store i32 %60, i32* %7
%61 = load i32, i32* %7
%62 = sub nsw i32 %61, 1
%63 = ashr i32 %62, 1
store i32 %63, i32* %8
%64 = call i32 @bl_uart_write_reg(i32 -1609629660, i32 3)
%65 = call i32 @bl_uart_read_reg(i32 -1609629684)
store i32 %65, i32* %9
%66 = load i32, i32* %9
%67 = or i32 %66, 128
%68 = call i32 @bl_uart_write_reg(i32 -1609629684, i32 %67)
%69 = load i32, i32* %6
%70 = and i32 %69, 255
%71 = call i32 @bl_uart_write_reg(i32 -1609629696, i32 %70)
%72 = load i32, i32* %6
%73 = ashr i32 %72, 8
%74 = and i32 %73, 255
%75 = call i32 @bl_uart_write_reg(i32 -1609629692, i32 %74)
%76 = load i32, i32* %9
%77 = call i32 @bl_uart_write_reg(i32 -1609629684, i32 %76)
%78 = load i32, i32* %7
%79 = call i32 @bl_uart_write_reg(i32 -1609629656, i32 %78)
%80 = load i32, i32* %8
%81 = call i32 @bl_uart_write_reg(i32 -1609629652, i32 %80)
%82 = load i32, i32* %5
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [10 x i32], [10 x i32]* %10, i64 0, i64 %83
%85 = load i32, i32* %84
%86 = call i32 @bl_uart_write_reg(i32 -1609629612, i32 %85)
%87 = load i32, i32* %5
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i64 0, i64 %88
%90 = load i32, i32* %89
%91 = call i32 @bl_uart_write_reg(i32 -1609629608, i32 %90)
%92 = call i32 @bl_uart_write_reg(i32 -1609629684, i32 3)
%93 = call i32 @bl_uart_write_reg(i32 -1609629688, i32 151)
%94 = call i32 @bl_uart_write_reg(i32 -1609629692, i32 0)
ret void
}

LLVM IR (-O2):
@__const.bl_uart_init.fraction_L_mapping = [10 x i32] [i32 0, i32 0, i32 32, i32 144, i32 168, i32 84, i32 108, i32 186, i32 246, i32 254]
define void @bl_uart_init(i32 %0) {
%2 = alloca [10 x i32]
%3 = bitcast [10 x i32]* %2 to i8*
%4 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 5
%5 = bitcast i32* %4 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %5
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 9
store i32 1, i32* %6
store volatile i32 255, i32* inttoptr (i64 2718043144 to i32*)
store volatile i32 51, i32* inttoptr (i64 2718043140 to i32*)
%7 = load volatile i32, i32* inttoptr (i64 2717975332 to i32*)
%8 = or i32 %7, 32768
store volatile i32 %8, i32* inttoptr (i64 2717975332 to i32*)
%9 = sdiv i32 %0, 29491200
%10 = sdiv i32 %0, 2949120
%11 = trunc i32 %10 to i16
%12 = srem i16 %11, 10
%13 = icmp ne i16 %12, 0
%14 = add i32 %0, 29491199
%15 = icmp ult i32 %14, 58982399
%16 = or i1 %15, %13
%17 = zext i1 %16 to i32
%18 = add nsw i32 %9, %17
br label %19
19: ; preds = %19, %1
%20 = phi i32 [ %18, %1 ], [ %24, %19 ]
%21 = mul nsw i32 %20, 115200
%22 = sdiv i32 %0, %21
%23 = icmp sgt i32 %22, 256
%24 = add nsw i32 %20, 1
br i1 %23, label %19, label %25
25: ; preds = %19
%26 = mul nsw i32 %0, 10
%27 = sdiv i32 %26, %21
%28 = srem i32 %27, 10
%29 = add nsw i32 %22, -1
%30 = add nsw i32 %22, -2
%31 = ashr i32 %30, 1
%32 = tail call i32 @bl_uart_write_reg(i32 -1609629660, i32 3)
%33 = tail call i32 @bl_uart_read_reg(i32 -1609629684)
%34 = or i32 %33, 128
%35 = tail call i32 @bl_uart_write_reg(i32 -1609629684, i32 %34)
%36 = and i32 %20, 255
%37 = tail call i32 @bl_uart_write_reg(i32 -1609629696, i32 %36)
%38 = lshr i32 %20, 8
%39 = and i32 %38, 255
%40 = tail call i32 @bl_uart_write_reg(i32 -1609629692, i32 %39)
%41 = tail call i32 @bl_uart_write_reg(i32 -1609629684, i32 %33)
%42 = tail call i32 @bl_uart_write_reg(i32 -1609629656, i32 %29)
%43 = tail call i32 @bl_uart_write_reg(i32 -1609629652, i32 %31)
%44 = sext i32 %28 to i64
%45 = getelementptr inbounds [10 x i32], [10 x i32]* @__const.bl_uart_init.fraction_L_mapping, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = tail call i32 @bl_uart_write_reg(i32 -1609629612, i32 %46)
%48 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %44
%49 = load i32, i32* %48
%50 = tail call i32 @bl_uart_write_reg(i32 -1609629608, i32 %49)
%51 = tail call i32 @bl_uart_write_reg(i32 -1609629684, i32 3)
%52 = tail call i32 @bl_uart_write_reg(i32 -1609629688, i32 151)
%53 = tail call i32 @bl_uart_write_reg(i32 -1609629692, i32 0)
ret void
}