void connect_gdb_stub() {
  outb(0x3F8 + 1, 0x00);
  outb(0x3F8 + 3, 0x80);
  outb(0x3F8 + 0, 0x0C);
  outb(0x3F8 + 1, 0x00);
  outb(0x3F8 + 3, 0x03);
  outb(0x3F8 + 2, 0xC7);
  outb(0x3F8 + 4, 0x08);
  set_debug_traps();
  printf("Waiting for Connection on Serial Port 1...");
  asm volatile("int3");
}


x86 assembly (clang, -O0):
<connect_gdb_stub>:
push   %rbp
mov    %rsp,%rbp
mov    $0x3f9,%edi
xor    %esi,%esi
mov    $0x0,%al
call   1040 <outb@plt>
mov    $0x3fb,%edi
mov    $0x80,%esi
mov    $0x0,%al
call   1040 <outb@plt>
mov    $0x3f8,%edi
mov    $0xc,%esi
mov    $0x0,%al
call   1040 <outb@plt>
mov    $0x3f9,%edi
xor    %esi,%esi
mov    $0x0,%al
call   1040 <outb@plt>
mov    $0x3fb,%edi
mov    $0x3,%esi
mov    $0x0,%al
call   1040 <outb@plt>
mov    $0x3fa,%edi
mov    $0xc7,%esi
mov    $0x0,%al
call   1040 <outb@plt>
mov    $0x3fc,%edi
mov    $0x8,%esi
mov    $0x0,%al
call   1040 <outb@plt>
mov    $0x0,%al
call   1050 <set_debug_traps@plt>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
int3
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect_gdb_stub>:
push   %rax
mov    $0x3f9,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <outb@plt>
mov    $0x3fb,%edi
mov    $0x80,%esi
xor    %eax,%eax
call   1040 <outb@plt>
mov    $0x3f8,%edi
mov    $0xc,%esi
xor    %eax,%eax
call   1040 <outb@plt>
mov    $0x3f9,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <outb@plt>
mov    $0x3fb,%edi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <outb@plt>
mov    $0x3fa,%edi
mov    $0xc7,%esi
xor    %eax,%eax
call   1040 <outb@plt>
mov    $0x3fc,%edi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <outb@plt>
xor    %eax,%eax
call   1050 <set_debug_traps@plt>
lea    0xe50(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
int3
pop    %rax
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Waiting for Connection on Serial Port 1...\00"
define void @connect_gdb_stub() {
%1 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 1017, i32 0)
%2 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 1019, i32 128)
%3 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 1016, i32 12)
%4 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 1017, i32 0)
%5 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 1019, i32 3)
%6 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 1018, i32 199)
%7 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 1020, i32 8)
%8 = call i32 (...) @set_debug_traps()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"Waiting for Connection on Serial Port 1...\00"
define void @connect_gdb_stub() {
%1 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 1017, i32 0)
%2 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 1019, i32 128)
%3 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 1016, i32 12)
%4 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 1017, i32 0)
%5 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 1019, i32 3)
%6 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 1018, i32 199)
%7 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 1020, i32 8)
%8 = tail call i32 (...) @set_debug_traps()
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
tail call void asm sideeffect "int3", "~{dirflag},~{fpsr},~{flags}"()
ret void
}