#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 int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ IOPi_init(int, int /*<<< orphan*/);
int /*<<< orphan*/ _IONBF;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read_bus(int);
int /*<<< orphan*/ set_bus_direction(int, int);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ write_bus(int, int);
int main(int argc, char **argv) {
  setvbuf(stdout, NULL, _IONBF, 0);
  IOPi_init(0x20, 0);
  write_bus(0x20, 0x0000);
  set_bus_direction(0x20, 0xFFFF);
  printf("Logic output Started \n");
  uint16_t x = read_bus(0x20);
  printf("Logic output Ended \n");
  (void)x;
  (void)argc;
  (void)argv;
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1060 <setvbuf@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1070 <IOPi_init@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1040 <write_bus@plt>
mov    $0x20,%edi
mov    $0xffff,%esi
call   1050 <set_bus_direction@plt>
lea    0xe3f(%rip),%rdi
call   1030 <printf@plt>
mov    $0x20,%edi
call   1080 <read_bus@plt>
mov    %eax,-0x14(%rbp)
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1060 <setvbuf@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1070 <IOPi_init@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1040 <write_bus@plt>
mov    $0x20,%edi
mov    $0xffff,%esi
call   1050 <set_bus_direction@plt>
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
mov    $0x20,%edi
call   1080 <read_bus@plt>
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [23 x i8] c"Logic output Started \0A\00"
@.str.1 = [21 x i8] c"Logic output Ended \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @stdout
%8 = load i32, i32* @_IONBF
%9 = call i32 @setvbuf(i32 %7, i32* null, i32 %8, i32 0)
%10 = call i32 @IOPi_init(i32 32, i32 0)
%11 = call i32 @write_bus(i32 32, i32 0)
%12 = call i32 @set_bus_direction(i32 32, i32 65535)
%13 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @read_bus(i32 32)
store i32 %14, i32* %6
%15 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@_IONBF = global i32 0
@str = [22 x i8] c"Logic output Started \00"
@str.2 = [20 x i8] c"Logic output Ended \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stdout
%4 = load i32, i32* @_IONBF
%5 = tail call i32 @setvbuf(i32 %3, i32* null, i32 %4, i32 0)
%6 = tail call i32 @IOPi_init(i32 32, i32 0)
%7 = tail call i32 @write_bus(i32 32, i32 0)
%8 = tail call i32 @set_bus_direction(i32 32, i32 65535)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @read_bus(i32 32)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.2, i64 0, i64 0))
ret i32 0
}