#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 calc_divisor(int);
int /*<<< orphan*/ serial_puts(int, char *);
void init_serial(unsigned int base) {
  int clock_divisor;
  if (base == 0x481A8000) {
    clock_divisor = calc_divisor(38400);
    (*((volatile unsigned int *)(base + 0x4))) = 0x0;
    serial_puts(0x44E09000, "Init4\n");
  } else {
    clock_divisor = calc_divisor(115200);
    (*((volatile unsigned int *)(base + 0x4))) = 0x0;
  }
  (*((volatile unsigned int *)(base + 0xC))) = 0x83;
  (*((volatile unsigned int *)(base + 0x0))) = clock_divisor & 0xff;
  (*((volatile unsigned int *)(base + 0x4))) = (clock_divisor >> 8) & 0xff;
  (*((volatile unsigned int *)(base + 0xC))) = (0x01 | 0x02);
  (*((volatile unsigned int *)(base + 0x10))) = 0x3;
  (*((volatile unsigned int *)(base + 0x8))) = (0x01 | 0x02 | 0x04);
}


x86 assembly (clang, -O0):
<init_serial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x481a8000,-0x4(%rbp)
jne    1169 <init_serial+0x49>
mov    $0x9600,%edi
call   1040 <calc_divisor@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4,%eax
mov    %eax,%eax
movl   $0x0,(%rax)
mov    $0x44e09000,%edi
lea    0xea1(%rip),%rsi
call   1030 <serial_puts@plt>
jmp    1184 <init_serial+0x64>
mov    $0x1c200,%edi
call   1040 <calc_divisor@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4,%eax
mov    %eax,%eax
movl   $0x0,(%rax)
mov    -0x4(%rbp),%eax
add    $0xc,%eax
mov    %eax,%eax
movl   $0x83,(%rax)
mov    -0x8(%rbp),%ecx
and    $0xff,%ecx
mov    -0x4(%rbp),%eax
add    $0x0,%eax
mov    %eax,%eax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x4(%rbp),%eax
add    $0x4,%eax
mov    %eax,%eax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
add    $0xc,%eax
mov    %eax,%eax
movl   $0x3,(%rax)
mov    -0x4(%rbp),%eax
add    $0x10,%eax
mov    %eax,%eax
movl   $0x3,(%rax)
mov    -0x4(%rbp),%eax
add    $0x8,%eax
mov    %eax,%eax
movl   $0x7,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_serial>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
cmp    $0x481a8000,%edi
jne    115a <init_serial+0x3a>
mov    $0x9600,%edi
call   1040 <calc_divisor@plt>
mov    %eax,%ebp
movl   $0x0,0x481a8004
lea    0xeb5(%rip),%rsi
mov    $0x44e09000,%edi
call   1030 <serial_puts@plt>
lea    0x4(%rbx),%edi
jmp    116f <init_serial+0x4f>
mov    $0x1c200,%edi
call   1040 <calc_divisor@plt>
mov    %eax,%ebp
lea    0x4(%rbx),%edi
movl   $0x0,(%rdi)
lea    0xc(%rbx),%ecx
movl   $0x83,(%rcx)
mov    %ebp,%eax
movzbl %al,%edx
mov    %ebx,%esi
mov    %edx,(%rsi)
movzbl %ah,%edx
mov    %edx,(%rdi)
movl   $0x3,(%rcx)
lea    0x10(%rbx),%eax
movl   $0x3,(%rax)
add    $0x8,%ebx
movl   $0x7,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"Init4\0A\00"
define void @init_serial(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp eq i32 %4, 1209696256
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = call i32 @calc_divisor(i32 38400)
store i32 %7, i32* %3
%8 = load i32, i32* %2
%9 = add i32 %8, 4
%10 = zext i32 %9 to i64
%11 = inttoptr i64 %10 to i32*
store volatile i32 0, i32* %11
%12 = call i32 @serial_puts(i32 1155567616, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %19
13: ; preds = %1
%14 = call i32 @calc_divisor(i32 115200)
store i32 %14, i32* %3
%15 = load i32, i32* %2
%16 = add i32 %15, 4
%17 = zext i32 %16 to i64
%18 = inttoptr i64 %17 to i32*
store volatile i32 0, i32* %18
br label %19
19: ; preds = %13, %6
%20 = load i32, i32* %2
%21 = add i32 %20, 12
%22 = zext i32 %21 to i64
%23 = inttoptr i64 %22 to i32*
store volatile i32 131, i32* %23
%24 = load i32, i32* %3
%25 = and i32 %24, 255
%26 = load i32, i32* %2
%27 = add i32 %26, 0
%28 = zext i32 %27 to i64
%29 = inttoptr i64 %28 to i32*
store volatile i32 %25, i32* %29
%30 = load i32, i32* %3
%31 = ashr i32 %30, 8
%32 = and i32 %31, 255
%33 = load i32, i32* %2
%34 = add i32 %33, 4
%35 = zext i32 %34 to i64
%36 = inttoptr i64 %35 to i32*
store volatile i32 %32, i32* %36
%37 = load i32, i32* %2
%38 = add i32 %37, 12
%39 = zext i32 %38 to i64
%40 = inttoptr i64 %39 to i32*
store volatile i32 3, i32* %40
%41 = load i32, i32* %2
%42 = add i32 %41, 16
%43 = zext i32 %42 to i64
%44 = inttoptr i64 %43 to i32*
store volatile i32 3, i32* %44
%45 = load i32, i32* %2
%46 = add i32 %45, 8
%47 = zext i32 %46 to i64
%48 = inttoptr i64 %47 to i32*
store volatile i32 7, i32* %48
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"Init4\0A\00"
define void @init_serial(i32 %0) {
%2 = icmp eq i32 %0, 1209696256
br i1 %2, label %3, label %9
3: ; preds = %1
%4 = tail call i32 @calc_divisor(i32 38400)
store volatile i32 0, i32* inttoptr (i64 1209696260 to i32*)
%5 = tail call i32 @serial_puts(i32 1155567616, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = add nuw nsw i32 %0, 4
%7 = zext i32 %6 to i64
%8 = inttoptr i64 %7 to i32*
br label %14
9: ; preds = %1
%10 = tail call i32 @calc_divisor(i32 115200)
%11 = add i32 %0, 4
%12 = zext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
store volatile i32 0, i32* %13
br label %14
14: ; preds = %9, %3
%15 = phi i32* [ %13, %9 ], [ %8, %3 ]
%16 = phi i32 [ %10, %9 ], [ %4, %3 ]
%17 = add i32 %0, 12
%18 = zext i32 %17 to i64
%19 = inttoptr i64 %18 to i32*
store volatile i32 131, i32* %19
%20 = and i32 %16, 255
%21 = zext i32 %0 to i64
%22 = inttoptr i64 %21 to i32*
store volatile i32 %20, i32* %22
%23 = lshr i32 %16, 8
%24 = and i32 %23, 255
store volatile i32 %24, i32* %15
store volatile i32 3, i32* %19
%25 = add i32 %0, 16
%26 = zext i32 %25 to i64
%27 = inttoptr i64 %26 to i32*
store volatile i32 3, i32* %27
%28 = add i32 %0, 8
%29 = zext i32 %28 to i64
%30 = inttoptr i64 %29 to i32*
store volatile i32 7, i32* %30
ret void
}