#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 */
char *getenv(char *);
int /*<<< orphan*/ printf(char *, void *);
long strtoul(char *, int /*<<< orphan*/ *, int);
long syscall(int, int, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  long iobase;
  char *p;
  iobase = syscall(200, 1, 0, 0);
  printf("PCI memory base address: %p\n", (void *)iobase);
  iobase = syscall(200, 2, 0, 0);
  printf("PCI I/O base address:    %p\n", (void *)iobase);
  iobase = syscall(200, 4, 0, 0);
  if ((p = getenv("SNAP_ISA_MEMBASE")) != NULL)
    iobase = strtoul(p, NULL, 16);
  printf("ISA memory base address: %p\n", (void *)iobase);
  iobase = syscall(200, 3, 0, 0);
  if ((p = getenv("SNAP_ISA_IOBASE")) != NULL)
    iobase = strtoul(p, NULL, 16);
  printf("ISA I/O base address:    %p\n", (void *)iobase);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xc8,%edi
mov    $0x1,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1050 <syscall@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
mov    $0xc8,%edi
mov    $0x2,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1050 <syscall@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
mov    $0xc8,%edi
mov    $0x4,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1050 <syscall@plt>
mov    %rax,-0x10(%rbp)
lea    0xe7f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11e4 <main+0xa4>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
mov    $0xc8,%edi
mov    $0x3,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1050 <syscall@plt>
mov    %rax,-0x10(%rbp)
lea    0xe56(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     123b <main+0xfb>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0xc8,%edi
mov    $0x1,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <syscall@plt>
lea    0xea5(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0xc8,%edi
mov    $0x2,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <syscall@plt>
lea    0xea0(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0xc8,%edi
mov    $0x4,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <syscall@plt>
mov    %rax,%rbx
lea    0xe98(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11be <main+0x7e>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %rax,%rbx
lea    0xe86(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0xc8,%edi
mov    $0x3,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <syscall@plt>
mov    %rax,%rbx
lea    0xe7e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1206 <main+0xc6>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %rax,%rbx
lea    0xe6b(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [29 x i8] c"PCI memory base address: %p\0A\00"
@.str.1 = [29 x i8] c"PCI I/O base address: %p\0A\00"
@.str.2 = [17 x i8] c"SNAP_ISA_MEMBASE\00"
@.str.3 = [29 x i8] c"ISA memory base address: %p\0A\00"
@.str.4 = [16 x i8] c"SNAP_ISA_IOBASE\00"
@.str.5 = [29 x i8] c"ISA I/O base address: %p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i64 @syscall(i32 200, i32 1, i32 0, i32 0)
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = inttoptr i64 %5 to i8*
%7 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = call i64 @syscall(i32 200, i32 2, i32 0, i32 0)
store i64 %8, i64* %2
%9 = load i64, i64* %2
%10 = inttoptr i64 %9 to i8*
%11 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i64 @syscall(i32 200, i32 4, i32 0, i32 0)
store i64 %12, i64* %2
%13 = call i8* @getenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i8* %13, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = load i8*, i8** %3
%17 = call i64 @strtoul(i8* %16, i32* null, i32 16)
store i64 %17, i64* %2
br label %18
18: ; preds = %15, %0
%19 = load i64, i64* %2
%20 = inttoptr i64 %19 to i8*
%21 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = call i64 @syscall(i32 200, i32 3, i32 0, i32 0)
store i64 %22, i64* %2
%23 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
store i8* %23, i8** %3
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = load i8*, i8** %3
%27 = call i64 @strtoul(i8* %26, i32* null, i32 16)
store i64 %27, i64* %2
br label %28
28: ; preds = %25, %18
%29 = load i64, i64* %2
%30 = inttoptr i64 %29 to i8*
%31 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [29 x i8] c"PCI memory base address: %p\0A\00"
@.str.1 = [29 x i8] c"PCI I/O base address: %p\0A\00"
@.str.2 = [17 x i8] c"SNAP_ISA_MEMBASE\00"
@.str.3 = [29 x i8] c"ISA memory base address: %p\0A\00"
@.str.4 = [16 x i8] c"SNAP_ISA_IOBASE\00"
@.str.5 = [29 x i8] c"ISA I/O base address: %p\0A\00"
define i32 @main() {
%1 = tail call i64 @syscall(i32 200, i32 1, i32 0, i32 0)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = tail call i64 @syscall(i32 200, i32 2, i32 0, i32 0)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%7 = tail call i64 @syscall(i32 200, i32 4, i32 0, i32 0)
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = tail call i64 @strtoul(i8* nocapture %8, i32* null, i32 16)
br label %12
12: ; preds = %10, %0
%13 = phi i64 [ %11, %10 ], [ %7, %0 ]
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %14)
%16 = tail call i64 @syscall(i32 200, i32 3, i32 0, i32 0)
%17 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %21, label %19
19: ; preds = %12
%20 = tail call i64 @strtoul(i8* nocapture %17, i32* null, i32 16)
br label %21
21: ; preds = %19, %12
%22 = phi i64 [ %20, %19 ], [ %16, %12 ]
%23 = inttoptr i64 %22 to i8*
%24 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %23)
ret i32 0
}