#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 uint16_t;

/* Variables and functions */
int /*<<< orphan*/ IOPi_init(int, int /*<<< orphan*/);
int /*<<< orphan*/ _IONBF;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_bus_direction(int, int);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  setvbuf(stdout, NULL, _IONBF, 0);
  IOPi_init(0x20, 0);
  printf("Logic output Started \n");
  for (uint16_t a = 0; a < 65535; a++) {
    set_bus_direction(0x20, a);
  }
  printf("Logic output Ended \n");
  (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    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1050 <setvbuf@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1060 <IOPi_init@plt>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xffff,-0x14(%rbp)
jge    11ba <main+0x7a>
mov    -0x14(%rbp),%esi
mov    $0x20,%edi
call   1040 <set_bus_direction@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1192 <main+0x52>
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    0x2e97(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
xor    %esi,%esi
xor    %ecx,%ecx
call   1050 <setvbuf@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1060 <IOPi_init@plt>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
mov    $0x20,%edi
mov    %ebx,%esi
call   1040 <set_bus_direction@plt>
add    $0x1,%ebx
cmp    $0xffff,%ebx
jne    1180 <main+0x40>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
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 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %12
12: ; preds = %18, %2
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 65535
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i32, i32* %6
%17 = call i32 @set_bus_direction(i32 32, i32 %16)
br label %18
18: ; preds = %15
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
br label %12
21: ; preds = %12
%22 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %4
%24 = 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %10
8: ; preds = %10
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.2, i64 0, i64 0))
ret i32 0
10: ; preds = %2, %10
%11 = phi i32 [ 0, %2 ], [ %13, %10 ]
%12 = tail call i32 @set_bus_direction(i32 32, i32 %11)
%13 = add nuw nsw i32 %11, 1
%14 = icmp eq i32 %13, 65535
br i1 %14, label %8, label %10
}