#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 char inb(int);
int /*<<< orphan*/ outb(unsigned char, int);
unsigned int probe_baud(int port) {
  unsigned char lcr, dll, dlh;
  unsigned int quot;
  lcr = inb(port + 3);
  outb(lcr | 0x80, port + 3);
  dll = inb(port + 0);
  dlh = inb(port + 1);
  outb(lcr, port + 3);
  quot = (dlh << 8) | dll;
  return (1843200 / 16) / quot;
}


x86 assembly (clang, -O0):
<probe_baud>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
add    $0x3,%edi
call   1040 <inb@plt>
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
or     $0x80,%eax
mov    -0x4(%rbp),%esi
add    $0x3,%esi
movzbl %al,%edi
call   1030 <outb@plt>
mov    -0x4(%rbp),%edi
add    $0x0,%edi
call   1040 <inb@plt>
mov    %al,-0x6(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
call   1040 <inb@plt>
mov    %al,-0x7(%rbp)
mov    -0x5(%rbp),%al
mov    -0x4(%rbp),%esi
add    $0x3,%esi
movzbl %al,%edi
call   1030 <outb@plt>
movzbl -0x7(%rbp),%eax
shl    $0x8,%eax
movzbl -0x6(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    $0x1c200,%eax
xor    %edx,%edx
divl   -0xc(%rbp)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<probe_baud>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x3(%rbx),%ebp
mov    %ebp,%edi
call   1040 <inb@plt>
mov    %eax,%r14d
or     $0x80,%al
movzbl %al,%edi
mov    %ebp,%esi
call   1030 <outb@plt>
mov    %ebx,%edi
call   1040 <inb@plt>
mov    %eax,%r15d
add    $0x1,%ebx
mov    %ebx,%edi
call   1040 <inb@plt>
mov    %eax,%ebx
movzbl %r14b,%edi
mov    %ebp,%esi
call   1030 <outb@plt>
movzbl %bl,%eax
shl    $0x8,%eax
movzbl %r15b,%ecx
or     %eax,%ecx
mov    $0x1c200,%eax
xor    %edx,%edx
div    %ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @probe_baud(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = add nsw i32 %7, 3
%9 = call zeroext i8 @inb(i32 %8)
store i8 %9, i8* %3
%10 = load i8, i8* %3
%11 = zext i8 %10 to i32
%12 = or i32 %11, 128
%13 = trunc i32 %12 to i8
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 3
%16 = call i32 @outb(i8 zeroext %13, i32 %15)
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 0
%19 = call zeroext i8 @inb(i32 %18)
store i8 %19, i8* %4
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
%22 = call zeroext i8 @inb(i32 %21)
store i8 %22, i8* %5
%23 = load i8, i8* %3
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 3
%26 = call i32 @outb(i8 zeroext %23, i32 %25)
%27 = load i8, i8* %5
%28 = zext i8 %27 to i32
%29 = shl i32 %28, 8
%30 = load i8, i8* %4
%31 = zext i8 %30 to i32
%32 = or i32 %29, %31
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = udiv i32 115200, %33
ret i32 %34
}

LLVM IR (-O2):
define i32 @probe_baud(i32 %0) {
%2 = add nsw i32 %0, 3
%3 = tail call zeroext i8 @inb(i32 %2)
%4 = or i8 %3, -128
%5 = tail call i32 @outb(i8 zeroext %4, i32 %2)
%6 = tail call zeroext i8 @inb(i32 %0)
%7 = add nsw i32 %0, 1
%8 = tail call zeroext i8 @inb(i32 %7)
%9 = tail call i32 @outb(i8 zeroext %3, i32 %2)
%10 = zext i8 %8 to i32
%11 = shl nuw nsw i32 %10, 8
%12 = zext i8 %6 to i32
%13 = or i32 %11, %12
%14 = udiv i32 115200, %13
ret i32 %14
}