#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 */
unsigned long SysCtlAPB1ClockGet();
unsigned long SysCtlAPB2ClockGet();
int /*<<< orphan*/ SysCtlPeripheralReset(int);
void UARTConfigSet(unsigned long ulBase, unsigned long ulBaud,
                   unsigned long ulConfig) {
  unsigned long ulExtClk, ultemp, uldiv;
  ;
  ;
  if (ulBase == 0x40013800) {
    SysCtlPeripheralReset(0x10004000);
  } else if (ulBase == 0x40004400) {
    SysCtlPeripheralReset(0x20100002);
  } else if (ulBase == 0x40004800) {
    SysCtlPeripheralReset(0x20100004);
  } else if (ulBase == 0x40004C00) {
    SysCtlPeripheralReset(0x20100008);
  } else {
    SysCtlPeripheralReset(0x20100010);
  }
  (*((volatile unsigned long *)(ulBase + 0x00000010))) &= ~0x00003000;
  (*((volatile unsigned long *)(ulBase + 0x00000010))) = ulConfig & 0x00003000;
  (*((volatile unsigned long *)(ulBase + 0x0000000C))) &=
      ~(0x00001000 | 0x00000400 | 0x00000200 | 0x00000008 | 0x00000004);
  (*((volatile unsigned long *)(ulBase + 0x0000000C))) =
      ulConfig & (0x00001000 | 0x00000600);
  if (ulBase == 0x40013800) {
    ulExtClk = SysCtlAPB2ClockGet();
  } else {
    ulExtClk = SysCtlAPB1ClockGet();
  }
  if (((*((volatile unsigned long *)(ulBase + 0x0000000C))) & 0) != 0) {
    ultemp = ((25 * ulExtClk) / (2 * (ulBaud)));
  } else {
    ultemp = ((25 * ulExtClk) / (4 * (ulBaud)));
  }
  uldiv = (ultemp / 100) << 4;
  ultemp = ultemp - (100 * (uldiv >> 4));
  if (((*((volatile unsigned long *)(ulBase + 0x0000000C))) & 0) != 0) {
    uldiv |= ((((ultemp * 8) + 50) / 100)) & ((unsigned char)0x07);
  } else {
    uldiv |= ((((ultemp * 16) + 50) / 100)) & ((unsigned char)0x0F);
  }
  (*((volatile unsigned long *)(ulBase + 0x00000008))) = uldiv;
}


x86 assembly (clang, -O0):
<UARTConfigSet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x40013800,-0x8(%rbp)
40
jne    1161 <UARTConfigSet+0x31>
mov    $0x10004000,%edi
call   1030 <SysCtlPeripheralReset@plt>
jmp    11d1 <UARTConfigSet+0xa1>
cmpq   $0x40004400,-0x8(%rbp)
40
jne    117e <UARTConfigSet+0x4e>
mov    $0x20100002,%edi
call   1030 <SysCtlPeripheralReset@plt>
jmp    11cc <UARTConfigSet+0x9c>
cmpq   $0x40004800,-0x8(%rbp)
40
jne    119b <UARTConfigSet+0x6b>
mov    $0x20100004,%edi
call   1030 <SysCtlPeripheralReset@plt>
jmp    11c7 <UARTConfigSet+0x97>
cmpq   $0x40004c00,-0x8(%rbp)
40
jne    11b8 <UARTConfigSet+0x88>
mov    $0x20100008,%edi
call   1030 <SysCtlPeripheralReset@plt>
jmp    11c2 <UARTConfigSet+0x92>
mov    $0x20100010,%edi
call   1030 <SysCtlPeripheralReset@plt>
jmp    11c7 <UARTConfigSet+0x97>
jmp    11cc <UARTConfigSet+0x9c>
jmp    11d1 <UARTConfigSet+0xa1>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rcx
and    $0xffffffffffffcfff,%rcx
mov    %rcx,0x10(%rax)
mov    -0x18(%rbp),%rcx
and    $0x3000,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%rcx
and    $0xffffffffffffe9f3,%rcx
mov    %rcx,0xc(%rax)
mov    -0x18(%rbp),%rcx
and    $0x1600,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0xc(%rax)
cmpq   $0x40013800,-0x8(%rbp)
40
jne    123b <UARTConfigSet+0x10b>
mov    $0x0,%al
call   1050 <SysCtlAPB2ClockGet@plt>
mov    %rax,-0x20(%rbp)
jmp    1246 <UARTConfigSet+0x116>
mov    $0x0,%al
call   1040 <SysCtlAPB1ClockGet@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%rax
and    $0x0,%rax
cmp    $0x0,%rax
je     1277 <UARTConfigSet+0x147>
imul   $0x19,-0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
shl    $0x1,%rcx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x28(%rbp)
jmp    128d <UARTConfigSet+0x15d>
imul   $0x19,-0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
shl    $0x2,%rcx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x64,%ecx
xor    %edx,%edx
div    %rcx
shl    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
shr    $0x4,%rcx
imul   $0x64,%rcx,%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%rax
and    $0x0,%rax
cmp    $0x0,%rax
je     12f7 <UARTConfigSet+0x1c7>
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
add    $0x32,%rax
mov    $0x64,%ecx
xor    %edx,%edx
div    %rcx
and    $0x7,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1319 <UARTConfigSet+0x1e9>
mov    -0x28(%rbp),%rax
shl    $0x4,%rax
add    $0x32,%rax
mov    $0x64,%ecx
xor    %edx,%edx
div    %rcx
and    $0xf,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UARTConfigSet>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x10004000,%edi
cmp    $0x40013800,%rbx
je     1181 <UARTConfigSet+0x51>
cmp    $0x40004400,%rbx
je     116e <UARTConfigSet+0x3e>
cmp    $0x40004c00,%rbx
je     1175 <UARTConfigSet+0x45>
cmp    $0x40004800,%rbx
jne    117c <UARTConfigSet+0x4c>
mov    $0x20100004,%edi
jmp    1181 <UARTConfigSet+0x51>
mov    $0x20100002,%edi
jmp    1181 <UARTConfigSet+0x51>
mov    $0x20100008,%edi
jmp    1181 <UARTConfigSet+0x51>
mov    $0x20100010,%edi
call   1030 <SysCtlPeripheralReset@plt>
andq   $0xffffffffffffcfff,0x10(%rbx)
ff
mov    %r15d,%eax
and    $0x3000,%eax
mov    %rax,0x10(%rbx)
andq   $0xffffffffffffe9f3,0xc(%rbx)
ff
and    $0x1600,%r15d
mov    %r15,0xc(%rbx)
xor    %eax,%eax
cmp    $0x40013800,%rbx
jne    11bf <UARTConfigSet+0x8f>
call   1050 <SysCtlAPB2ClockGet@plt>
jmp    11c4 <UARTConfigSet+0x94>
call   1040 <SysCtlAPB1ClockGet@plt>
mov    0xc(%rbx),%rcx
lea    (%rax,%rax,4),%rax
lea    (%rax,%rax,4),%rax
shl    $0x2,%r14
mov    %rax,%rcx
or     %r14,%rcx
shr    $0x20,%rcx
je     11ea <UARTConfigSet+0xba>
xor    %edx,%edx
div    %r14
mov    %rax,%rcx
jmp    11f1 <UARTConfigSet+0xc1>
xor    %edx,%edx
div    %r14d
mov    %eax,%ecx
mov    %rcx,%rax
shr    $0x2,%rax
movabs $0x28f5c28f5c28f5c3,%rdi
c2 f5 28
mul    %rdi
mov    %rdx,%rsi
shr    $0x2,%rsi
mov    0xc(%rbx),%rax
imul   $0xffffffffffffff9c,%rsi,%rax
shl    $0x4,%rsi
add    %rcx,%rax
shl    $0x4,%rax
add    $0x32,%rax
shr    $0x2,%rax
mul    %rdi
shr    $0x2,%edx
and    $0xf,%edx
or     %rsi,%rdx
mov    %rdx,0x8(%rbx)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @UARTConfigSet(i64 %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%10 = load i64, i64* %4
%11 = icmp eq i64 %10, 1073821696
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @SysCtlPeripheralReset(i32 268451840)
br label %34
14: ; preds = %3
%15 = load i64, i64* %4
%16 = icmp eq i64 %15, 1073759232
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @SysCtlPeripheralReset(i32 537919490)
br label %33
19: ; preds = %14
%20 = load i64, i64* %4
%21 = icmp eq i64 %20, 1073760256
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @SysCtlPeripheralReset(i32 537919492)
br label %32
24: ; preds = %19
%25 = load i64, i64* %4
%26 = icmp eq i64 %25, 1073761280
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @SysCtlPeripheralReset(i32 537919496)
br label %31
29: ; preds = %24
%30 = call i32 @SysCtlPeripheralReset(i32 537919504)
br label %31
31: ; preds = %29, %27
br label %32
32: ; preds = %31, %22
br label %33
33: ; preds = %32, %17
br label %34
34: ; preds = %33, %12
%35 = load i64, i64* %4
%36 = add i64 %35, 16
%37 = inttoptr i64 %36 to i64*
%38 = load volatile i64, i64* %37
%39 = and i64 %38, -12289
store volatile i64 %39, i64* %37
%40 = load i64, i64* %6
%41 = and i64 %40, 12288
%42 = load i64, i64* %4
%43 = add i64 %42, 16
%44 = inttoptr i64 %43 to i64*
store volatile i64 %41, i64* %44
%45 = load i64, i64* %4
%46 = add i64 %45, 12
%47 = inttoptr i64 %46 to i64*
%48 = load volatile i64, i64* %47
%49 = and i64 %48, -5645
store volatile i64 %49, i64* %47
%50 = load i64, i64* %6
%51 = and i64 %50, 5632
%52 = load i64, i64* %4
%53 = add i64 %52, 12
%54 = inttoptr i64 %53 to i64*
store volatile i64 %51, i64* %54
%55 = load i64, i64* %4
%56 = icmp eq i64 %55, 1073821696
br i1 %56, label %57, label %59
57: ; preds = %34
%58 = call i64 (...) @SysCtlAPB2ClockGet()
store i64 %58, i64* %7
br label %61
59: ; preds = %34
%60 = call i64 (...) @SysCtlAPB1ClockGet()
store i64 %60, i64* %7
br label %61
61: ; preds = %59, %57
%62 = load i64, i64* %4
%63 = add i64 %62, 12
%64 = inttoptr i64 %63 to i64*
%65 = load volatile i64, i64* %64
%66 = and i64 %65, 0
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %74
68: ; preds = %61
%69 = load i64, i64* %7
%70 = mul i64 25, %69
%71 = load i64, i64* %5
%72 = mul i64 2, %71
%73 = udiv i64 %70, %72
store i64 %73, i64* %8
br label %80
74: ; preds = %61
%75 = load i64, i64* %7
%76 = mul i64 25, %75
%77 = load i64, i64* %5
%78 = mul i64 4, %77
%79 = udiv i64 %76, %78
store i64 %79, i64* %8
br label %80
80: ; preds = %74, %68
%81 = load i64, i64* %8
%82 = udiv i64 %81, 100
%83 = shl i64 %82, 4
store i64 %83, i64* %9
%84 = load i64, i64* %8
%85 = load i64, i64* %9
%86 = lshr i64 %85, 4
%87 = mul i64 100, %86
%88 = sub i64 %84, %87
store i64 %88, i64* %8
%89 = load i64, i64* %4
%90 = add i64 %89, 12
%91 = inttoptr i64 %90 to i64*
%92 = load volatile i64, i64* %91
%93 = and i64 %92, 0
%94 = icmp ne i64 %93, 0
br i1 %94, label %95, label %103
95: ; preds = %80
%96 = load i64, i64* %8
%97 = mul i64 %96, 8
%98 = add i64 %97, 50
%99 = udiv i64 %98, 100
%100 = and i64 %99, 7
%101 = load i64, i64* %9
%102 = or i64 %101, %100
store i64 %102, i64* %9
br label %111
103: ; preds = %80
%104 = load i64, i64* %8
%105 = mul i64 %104, 16
%106 = add i64 %105, 50
%107 = udiv i64 %106, 100
%108 = and i64 %107, 15
%109 = load i64, i64* %9
%110 = or i64 %109, %108
store i64 %110, i64* %9
br label %111
111: ; preds = %103, %95
%112 = load i64, i64* %9
%113 = load i64, i64* %4
%114 = add i64 %113, 8
%115 = inttoptr i64 %114 to i64*
store volatile i64 %112, i64* %115
ret void
}

LLVM IR (-O2):
define void @UARTConfigSet(i64 %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %0, 1073821696
br i1 %4, label %9, label %5
5: ; preds = %3
switch i64 %0, label %8 [
i64 1073759232, label %9
i64 1073760256, label %6
i64 1073761280, label %7
]
6: ; preds = %5
br label %9
7: ; preds = %5
br label %9
8: ; preds = %5
br label %9
9: ; preds = %5, %3, %7, %8, %6
%10 = phi i32 [ 537919496, %7 ], [ 537919504, %8 ], [ 537919492, %6 ], [ 268451840, %3 ], [ 537919490, %5 ]
%11 = tail call i32 @SysCtlPeripheralReset(i32 %10)
%12 = add i64 %0, 16
%13 = inttoptr i64 %12 to i64*
%14 = load volatile i64, i64* %13
%15 = and i64 %14, -12289
store volatile i64 %15, i64* %13
%16 = and i64 %2, 12288
store volatile i64 %16, i64* %13
%17 = add i64 %0, 12
%18 = inttoptr i64 %17 to i64*
%19 = load volatile i64, i64* %18
%20 = and i64 %19, -5645
store volatile i64 %20, i64* %18
%21 = and i64 %2, 5632
store volatile i64 %21, i64* %18
br i1 %4, label %22, label %24
22: ; preds = %9
%23 = tail call i64 (...) @SysCtlAPB2ClockGet()
br label %26
24: ; preds = %9
%25 = tail call i64 (...) @SysCtlAPB1ClockGet()
br label %26
26: ; preds = %24, %22
%27 = phi i64 [ %23, %22 ], [ %25, %24 ]
%28 = load volatile i64, i64* %18
%29 = mul i64 %27, 25
%30 = shl i64 %1, 2
%31 = udiv i64 %29, %30
%32 = udiv i64 %31, 100
%33 = load volatile i64, i64* %18
%34 = shl nuw nsw i64 %32, 4
%35 = mul i64 %32, -100
%36 = add i64 %35, %31
%37 = shl i64 %36, 4
%38 = add i64 %37, 50
%39 = udiv i64 %38, 100
%40 = and i64 %39, 15
%41 = or i64 %40, %34
%42 = add i64 %0, 8
%43 = inttoptr i64 %42 to i64*
store volatile i64 %41, i64* %43
ret void
}