#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 *);
int read_val(int);
int /*<<< orphan*/ set_2bit(int, int, int);
int /*<<< orphan*/ set_one(int, int);
int /*<<< orphan*/ set_zero(int, int);
int /*<<< orphan*/ udelay(int);
void ac97_init(void) {
  set_one(0x7F001000, 0);
  udelay(1000);
  set_zero(0x7F001000, 0);
  udelay(1000);
  set_2bit(0x7F001000, 1, 0x3);
  udelay(1000);
  set_zero(0x7F001000, 1);
  udelay(1000);
  set_one(0x7F001000, 12);
  udelay(1000);
  set_one(0x7F001000, 3);
  set_one(0x7F001008, 23);
  udelay(1000);
  if ((read_val(0x7F001004) & 3) == 3)
    printf("ac97 has been active ...\n");
  else
    printf("ac97 init failed ...\n");
}


x86 assembly (clang, -O0):
<ac97_init>:
push   %rbp
mov    %rsp,%rbp
mov    $0x7f001000,%edi
xor    %esi,%esi
call   1040 <set_one@plt>
mov    $0x3e8,%edi
call   1080 <udelay@plt>
mov    $0x7f001000,%edi
xor    %esi,%esi
call   1060 <set_zero@plt>
mov    $0x3e8,%edi
call   1080 <udelay@plt>
mov    $0x7f001000,%edi
mov    $0x1,%esi
mov    $0x3,%edx
call   1050 <set_2bit@plt>
mov    $0x3e8,%edi
call   1080 <udelay@plt>
mov    $0x7f001000,%edi
mov    $0x1,%esi
call   1060 <set_zero@plt>
mov    $0x3e8,%edi
call   1080 <udelay@plt>
mov    $0x7f001000,%edi
mov    $0xc,%esi
call   1040 <set_one@plt>
mov    $0x3e8,%edi
call   1080 <udelay@plt>
mov    $0x7f001000,%edi
mov    $0x3,%esi
call   1040 <set_one@plt>
mov    $0x7f001008,%edi
mov    $0x17,%esi
call   1040 <set_one@plt>
mov    $0x3e8,%edi
call   1080 <udelay@plt>
mov    $0x7f001004,%edi
call   1070 <read_val@plt>
and    $0x3,%eax
cmp    $0x3,%eax
jne    122f <ac97_init+0xcf>
lea    0xddb(%rip),%rdi
call   1030 <printf@plt>
jmp    123b <ac97_init+0xdb>
lea    0xde4(%rip),%rdi
call   1030 <printf@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<ac97_init>:
push   %rax
mov    $0x7f001000,%edi
xor    %esi,%esi
call   1040 <set_one@plt>
mov    $0x3e8,%edi
call   1080 <udelay@plt>
mov    $0x7f001000,%edi
xor    %esi,%esi
call   1060 <set_zero@plt>
mov    $0x3e8,%edi
call   1080 <udelay@plt>
mov    $0x7f001000,%edi
mov    $0x1,%esi
mov    $0x3,%edx
call   1050 <set_2bit@plt>
mov    $0x3e8,%edi
call   1080 <udelay@plt>
mov    $0x7f001000,%edi
mov    $0x1,%esi
call   1060 <set_zero@plt>
mov    $0x3e8,%edi
call   1080 <udelay@plt>
mov    $0x7f001000,%edi
mov    $0xc,%esi
call   1040 <set_one@plt>
mov    $0x3e8,%edi
call   1080 <udelay@plt>
mov    $0x7f001000,%edi
mov    $0x3,%esi
call   1040 <set_one@plt>
mov    $0x7f001008,%edi
mov    $0x17,%esi
call   1040 <set_one@plt>
mov    $0x3e8,%edi
call   1080 <udelay@plt>
mov    $0x7f001004,%edi
call   1070 <read_val@plt>
not    %eax
test   $0x3,%al
lea    0xdfb(%rip),%rax
lea    0xddf(%rip),%rdi
cmove  %rax,%rdi
pop    %rax
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"ac97 has been active ...\0A\00"
@.str.1 = [22 x i8] c"ac97 init failed ...\0A\00"
define void @ac97_init() {
%1 = call i32 @set_one(i32 2130710528, i32 0)
%2 = call i32 @udelay(i32 1000)
%3 = call i32 @set_zero(i32 2130710528, i32 0)
%4 = call i32 @udelay(i32 1000)
%5 = call i32 @set_2bit(i32 2130710528, i32 1, i32 3)
%6 = call i32 @udelay(i32 1000)
%7 = call i32 @set_zero(i32 2130710528, i32 1)
%8 = call i32 @udelay(i32 1000)
%9 = call i32 @set_one(i32 2130710528, i32 12)
%10 = call i32 @udelay(i32 1000)
%11 = call i32 @set_one(i32 2130710528, i32 3)
%12 = call i32 @set_one(i32 2130710536, i32 23)
%13 = call i32 @udelay(i32 1000)
%14 = call i32 @read_val(i32 2130710532)
%15 = and i32 %14, 3
%16 = icmp eq i32 %15, 3
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %21
19: ; preds = %0
%20 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %17
ret void
}

LLVM IR (-O2):
@str = [21 x i8] c"ac97 init failed ...\00"
@str.2 = [25 x i8] c"ac97 has been active ...\00"
define void @ac97_init() {
%1 = tail call i32 @set_one(i32 2130710528, i32 0)
%2 = tail call i32 @udelay(i32 1000)
%3 = tail call i32 @set_zero(i32 2130710528, i32 0)
%4 = tail call i32 @udelay(i32 1000)
%5 = tail call i32 @set_2bit(i32 2130710528, i32 1, i32 3)
%6 = tail call i32 @udelay(i32 1000)
%7 = tail call i32 @set_zero(i32 2130710528, i32 1)
%8 = tail call i32 @udelay(i32 1000)
%9 = tail call i32 @set_one(i32 2130710528, i32 12)
%10 = tail call i32 @udelay(i32 1000)
%11 = tail call i32 @set_one(i32 2130710528, i32 3)
%12 = tail call i32 @set_one(i32 2130710536, i32 23)
%13 = tail call i32 @udelay(i32 1000)
%14 = tail call i32 @read_val(i32 2130710532)
%15 = and i32 %14, 3
%16 = icmp eq i32 %15, 3
%17 = select i1 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @str.2, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0)
%18 = tail call i32 @puts(i8* dereferenceable(1) %17)
ret void
}