#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*/ fail(int);
int /*<<< orphan*/ report_device(int);
int gpio_test(int addr) {
  volatile int *pio = (int *)addr;
  int mask;
  int width;
  report_device(0x0101a000);
  pio[3] = 0;
  pio[2] = 0;
  pio[1] = 0;
  pio[2] = 0xFFFFFFFF;
  mask = 0;
  width = 0;
  while (((pio[2] >> width) & 1) && (width <= 32)) {
    mask = mask | (1 << width);
    width++;
  }
  pio[2] = mask;
  if ((pio[0] & mask) != 0)
    fail(1);
  pio[1] = 0x89ABCDEF;
  if ((pio[0] & mask) != (0x89ABCDEF & mask))
    fail(2);
  pio[2] = 0;
}


x86 assembly (clang, -O0):
<gpio_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movslq -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x101a000,%edi
call   1030 <report_device@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,0xc(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x10(%rbp),%rax
movl   $0xffffffff,0x8(%rax)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    -0x18(%rbp),%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0x1,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     11a0 <gpio_test+0x80>
cmpl   $0x20,-0x18(%rbp)
setle  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11b0 <gpio_test+0x90>
jmp    11d2 <gpio_test+0xb2>
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1177 <gpio_test+0x57>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    -0x14(%rbp),%eax
cmp    $0x0,%eax
je     11f8 <gpio_test+0xd8>
mov    $0x1,%edi
call   1040 <fail@plt>
mov    -0x10(%rbp),%rax
movl   $0x89abcdef,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    -0x14(%rbp),%eax
mov    -0x14(%rbp),%ecx
and    $0x89abcdef,%ecx
cmp    %ecx,%eax
je     1227 <gpio_test+0x107>
mov    $0x2,%edi
call   1040 <fail@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_test>:
push   %rbp
push   %rbx
push   %rax
movslq %edi,%rbx
mov    $0x101a000,%edi
call   1030 <report_device@plt>
movl   $0x0,0xc(%rbx)
movl   $0x0,0x8(%rbx)
movl   $0x0,0x4(%rbx)
movl   $0xffffffff,0x8(%rbx)
xor    %ebp,%ebp
testl  $0x1,0x8(%rbx)
je     117e <gpio_test+0x5e>
xor    %ecx,%ecx
mov    $0x1,%eax
xor    %ebp,%ebp
mov    %ebp,%edx
mov    %eax,%ebp
mov    $0x2,%eax
shl    %cl,%eax
or     %edx,%ebp
mov    0x8(%rbx),%edx
and    %eax,%edx
je     117e <gpio_test+0x5e>
lea    0x1(%rcx),%edx
cmp    $0x20,%ecx
mov    %edx,%ecx
jb     1160 <gpio_test+0x40>
mov    %ebp,0x8(%rbx)
mov    (%rbx),%eax
and    %ebp,%eax
je     1191 <gpio_test+0x71>
mov    $0x1,%edi
call   1040 <fail@plt>
movl   $0x89abcdef,0x4(%rbx)
mov    $0x89abcdef,%eax
xor    (%rbx),%eax
test   %ebp,%eax
je     11ad <gpio_test+0x8d>
mov    $0x2,%edi
call   1040 <fail@plt>
movl   $0x0,0x8(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gpio_test(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i32*
store i32* %9, i32** %4
%10 = call i32 @report_device(i32 16883712)
%11 = load i32*, i32** %4
%12 = getelementptr inbounds i32, i32* %11, i64 3
store volatile i32 0, i32* %12
%13 = load i32*, i32** %4
%14 = getelementptr inbounds i32, i32* %13, i64 2
store volatile i32 0, i32* %14
%15 = load i32*, i32** %4
%16 = getelementptr inbounds i32, i32* %15, i64 1
store volatile i32 0, i32* %16
%17 = load i32*, i32** %4
%18 = getelementptr inbounds i32, i32* %17, i64 2
store volatile i32 -1, i32* %18
store i32 0, i32* %5
store i32 0, i32* %6
br label %19
19: ; preds = %32, %1
%20 = load i32*, i32** %4
%21 = getelementptr inbounds i32, i32* %20, i64 2
%22 = load volatile i32, i32* %21
%23 = load i32, i32* %6
%24 = ashr i32 %22, %23
%25 = and i32 %24, 1
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = load i32, i32* %6
%29 = icmp sle i32 %28, 32
br label %30
30: ; preds = %27, %19
%31 = phi i1 [ false, %19 ], [ %29, %27 ]
br i1 %31, label %32, label %39
32: ; preds = %30
%33 = load i32, i32* %5
%34 = load i32, i32* %6
%35 = shl i32 1, %34
%36 = or i32 %33, %35
store i32 %36, i32* %5
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %19
39: ; preds = %30
%40 = load i32, i32* %5
%41 = load i32*, i32** %4
%42 = getelementptr inbounds i32, i32* %41, i64 2
store volatile i32 %40, i32* %42
%43 = load i32*, i32** %4
%44 = getelementptr inbounds i32, i32* %43, i64 0
%45 = load volatile i32, i32* %44
%46 = load i32, i32* %5
%47 = and i32 %45, %46
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %39
%50 = call i32 @fail(i32 1)
br label %51
51: ; preds = %49, %39
%52 = load i32*, i32** %4
%53 = getelementptr inbounds i32, i32* %52, i64 1
store volatile i32 -1985229329, i32* %53
%54 = load i32*, i32** %4
%55 = getelementptr inbounds i32, i32* %54, i64 0
%56 = load volatile i32, i32* %55
%57 = load i32, i32* %5
%58 = and i32 %56, %57
%59 = load i32, i32* %5
%60 = and i32 -1985229329, %59
%61 = icmp ne i32 %58, %60
br i1 %61, label %62, label %64
62: ; preds = %51
%63 = call i32 @fail(i32 2)
br label %64
64: ; preds = %62, %51
%65 = load i32*, i32** %4
%66 = getelementptr inbounds i32, i32* %65, i64 2
store volatile i32 0, i32* %66
%67 = load i32, i32* %2
ret i32 %67
}

LLVM IR (-O2):
define i32 @gpio_test(i32 %0) {
%2 = sext i32 %0 to i64
%3 = inttoptr i64 %2 to i32*
%4 = tail call i32 @report_device(i32 16883712)
%5 = getelementptr inbounds i32, i32* %3, i64 3
store volatile i32 0, i32* %5
%6 = getelementptr inbounds i32, i32* %3, i64 2
store volatile i32 0, i32* %6
%7 = getelementptr inbounds i32, i32* %3, i64 1
store volatile i32 0, i32* %7
store volatile i32 -1, i32* %6
%8 = load volatile i32, i32* %6
%9 = and i32 %8, 1
%10 = icmp eq i32 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %1, %11
%12 = phi i32 [ %18, %11 ], [ 1, %1 ]
%13 = phi i32 [ %16, %11 ], [ 0, %1 ]
%14 = phi i32 [ %15, %11 ], [ 0, %1 ]
%15 = or i32 %12, %14
%16 = add nuw nsw i32 %13, 1
%17 = load volatile i32, i32* %6
%18 = shl i32 2, %13
%19 = and i32 %17, %18
%20 = icmp ne i32 %19, 0
%21 = icmp ult i32 %13, 32
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %11, label %23
23: ; preds = %11, %1
%24 = phi i32 [ 0, %1 ], [ %15, %11 ]
store volatile i32 %24, i32* %6
%25 = load volatile i32, i32* %3
%26 = and i32 %25, %24
%27 = icmp eq i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %23
%29 = tail call i32 @fail(i32 1)
br label %30
30: ; preds = %28, %23
store volatile i32 -1985229329, i32* %7
%31 = load volatile i32, i32* %3
%32 = xor i32 %31, -1985229329
%33 = and i32 %32, %24
%34 = icmp eq i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %30
%36 = tail call i32 @fail(i32 2)
br label %37
37: ; preds = %35, %30
store volatile i32 0, i32* %6
ret i32 undef
}