#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 */
int /*<<< orphan*/ printf(char *, unsigned int volatile);
void toggle_io(volatile unsigned int *port) {
  while (1) {
    *port = 0x00000000;
    printf("reg val = %x  \n", *port);
    *port = 0x00000004;
    printf("reg val = %x  \n", *port);
    *port = 0x00000008;
    printf("reg val = %x  \n", *port);
    *port = 0x0000000C;
    printf("reg val = %x  \n", *port);
  }
}


x86 assembly (clang, -O0):
<toggle_io>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xecd(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movl   $0x8,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movl   $0xc,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
jmp    111c <toggle_io+0xc>

x86 assembly (clang, -O2):
<toggle_io>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xee2(%rip),%r14
xchg   %ax,%ax
movl   $0x0,(%rbx)
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movl   $0x4,(%rbx)
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movl   $0x8,(%rbx)
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movl   $0xc,(%rbx)
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
jmp    1120 <toggle_io+0x10>

LLVM IR (-O0):
@.str = [16 x i8] c"reg val = %x \0A\00"
define void @toggle_io(i32* %0) {
%2 = alloca i32*
store i32* %0, i32** %2
br label %3
3: ; preds = %1, %3
%4 = load i32*, i32** %2
store volatile i32 0, i32* %4
%5 = load i32*, i32** %2
%6 = load volatile i32, i32* %5
%7 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32*, i32** %2
store volatile i32 4, i32* %8
%9 = load i32*, i32** %2
%10 = load volatile i32, i32* %9
%11 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32*, i32** %2
store volatile i32 8, i32* %12
%13 = load i32*, i32** %2
%14 = load volatile i32, i32* %13
%15 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32*, i32** %2
store volatile i32 12, i32* %16
%17 = load i32*, i32** %2
%18 = load volatile i32, i32* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %3
}

LLVM IR (-O2):
@.str = [16 x i8] c"reg val = %x \0A\00"
define void @toggle_io(i32* %0) {
br label %2
2: ; preds = %1, %2
store volatile i32 0, i32* %0
%3 = load volatile i32, i32* %0
%4 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %3)
store volatile i32 4, i32* %0
%5 = load volatile i32, i32* %0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %5)
store volatile i32 8, i32* %0
%7 = load volatile i32, i32* %0
%8 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %7)
store volatile i32 12, i32* %0
%9 = load volatile i32, i32* %0
%10 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %2
}