#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 unsigned char BR_constant;

/* Variables and functions */
int VPB_get_speed();
unsigned int serial_setbaud_(volatile unsigned char *UART,
                             unsigned int baudrate) {
  unsigned int BR_constant;
  unsigned int real_baudrate;
  unsigned char lcr_data;
  BR_constant = VPB_get_speed() / (16 * baudrate);
  real_baudrate = VPB_get_speed() / (16 * BR_constant);
  lcr_data = UART[0x0C];
  UART[0x0C] = lcr_data | (1 << 7);
  UART[0x04] = (BR_constant >> 8) & 0xff;
  UART[0x00] = (BR_constant)&0xff;
  UART[0x0C] = lcr_data & (~(1 << 7));
  return real_baudrate;
}


x86 assembly (clang, -O0):
<serial_setbaud_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1030 <VPB_get_speed@plt>
mov    -0xc(%rbp),%ecx
shl    $0x4,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <VPB_get_speed@plt>
mov    -0x10(%rbp),%ecx
shl    $0x4,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%al
mov    %al,-0x15(%rbp)
movzbl -0x15(%rbp),%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0xc(%rax)
mov    -0x10(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x10(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
movzbl -0x15(%rbp),%eax
and    $0xffffff7f,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0xc(%rax)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_setbaud_>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <VPB_get_speed@plt>
shl    $0x4,%ebp
xor    %edx,%edx
div    %ebp
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <VPB_get_speed@plt>
mov    %ebp,%ecx
shl    $0x4,%ecx
xor    %edx,%edx
div    %ecx
mov    0xc(%rbx),%cl
mov    %ecx,%edx
or     $0x80,%dl
mov    %dl,0xc(%rbx)
mov    %ebp,%edx
mov    %dh,0x4(%rbx)
mov    %dl,(%rbx)
and    $0x7f,%cl
mov    %cl,0xc(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @serial_setbaud_(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = call i32 (...) @VPB_get_speed()
%9 = load i32, i32* %4
%10 = mul i32 16, %9
%11 = udiv i32 %8, %10
store i32 %11, i32* %5
%12 = call i32 (...) @VPB_get_speed()
%13 = load i32, i32* %5
%14 = mul i32 16, %13
%15 = udiv i32 %12, %14
store i32 %15, i32* %6
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 12
%18 = load volatile i8, i8* %17
store i8 %18, i8* %7
%19 = load i8, i8* %7
%20 = zext i8 %19 to i32
%21 = or i32 %20, 128
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 12
store volatile i8 %22, i8* %24
%25 = load i32, i32* %5
%26 = lshr i32 %25, 8
%27 = and i32 %26, 255
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i64 4
store volatile i8 %28, i8* %30
%31 = load i32, i32* %5
%32 = and i32 %31, 255
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i64 0
store volatile i8 %33, i8* %35
%36 = load i8, i8* %7
%37 = zext i8 %36 to i32
%38 = and i32 %37, -129
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %3
%41 = getelementptr inbounds i8, i8* %40, i64 12
store volatile i8 %39, i8* %41
%42 = load i32, i32* %6
ret i32 %42
}

LLVM IR (-O2):
define i32 @serial_setbaud_(i8* %0, i32 %1) {
%3 = tail call i32 (...) @VPB_get_speed()
%4 = shl i32 %1, 4
%5 = udiv i32 %3, %4
%6 = tail call i32 (...) @VPB_get_speed()
%7 = shl i32 %5, 4
%8 = udiv i32 %6, %7
%9 = getelementptr inbounds i8, i8* %0, i64 12
%10 = load volatile i8, i8* %9
%11 = or i8 %10, -128
store volatile i8 %11, i8* %9
%12 = lshr i32 %5, 8
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds i8, i8* %0, i64 4
store volatile i8 %13, i8* %14
%15 = trunc i32 %5 to i8
store volatile i8 %15, i8* %0
%16 = and i8 %10, 127
store volatile i8 %16, i8* %9
ret i32 %8
}