#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 scalar_t__ uint32_t;

/* Variables and functions */
int Dump3DCapabilities(int, int);
int Dump3DParameters(int, int);
int DumpFifoStuff(scalar_t__ const *, scalar_t__, int);
int FindAndMapFifo(scalar_t__ const **, scalar_t__ *, int);
int /*<<< orphan*/ O_RDWR;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int rcExit = 0;
  const char *pszDev = "/dev/dri/card0";
  if (argc == 2)
    pszDev = argv[1];
  int fd = open(pszDev, O_RDWR);
  if (fd != -1) {
    uint32_t const *pau32Fifo = NULL;
    uint32_t cbFifo = 0;
    rcExit = Dump3DParameters(fd, rcExit);
    rcExit = Dump3DCapabilities(fd, rcExit);
    rcExit = FindAndMapFifo(&pau32Fifo, &cbFifo, rcExit);
    if (pau32Fifo && cbFifo)
      rcExit = DumpFifoStuff(pau32Fifo, cbFifo, rcExit);
  } else {
    fprintf(stderr, "error opening '%s': %d\n", pszDev, errno);
    rcExit = 1;
  }
  return rcExit;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe7c(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    119e <main+0x3e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     122a <main+0xca>
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1060 <Dump3DParameters@plt>
mov    %eax,-0x14(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <Dump3DCapabilities@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edx
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1030 <FindAndMapFifo@plt>
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1225 <main+0xc5>
cmpq   $0x0,-0x38(%rbp)
je     1225 <main+0xc5>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <DumpFifoStuff@plt>
mov    %eax,-0x14(%rbp)
jmp    1253 <main+0xf3>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    0x2d92(%rip),%rax
mov    (%rax),%ecx
lea    0xdc8(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    1171 <main+0x11>
mov    0x8(%rsi),%rbx
jmp    1178 <main+0x18>
lea    0xe88(%rip),%rbx
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     11e2 <main+0x82>
mov    %eax,%ebp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    %eax,%edi
xor    %esi,%esi
call   1060 <Dump3DParameters@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <Dump3DCapabilities@plt>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %eax,%edx
call   1030 <FindAndMapFifo@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     1208 <main+0xa8>
mov    0x8(%rsp),%rsi
test   %rsi,%rsi
je     1208 <main+0xa8>
mov    %eax,%edx
call   1050 <DumpFifoStuff@plt>
jmp    1208 <main+0xa8>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    0x2dde(%rip),%rax
mov    (%rax),%ecx
lea    0xe14(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/dri/card0\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"error opening '%s': %d\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %7
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %7
br label %17
17: ; preds = %13, %2
%18 = load i8*, i8** %7
%19 = load i32, i32* @O_RDWR
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %43
23: ; preds = %17
store i64* null, i64** %9
store i64 0, i64* %10
%24 = load i32, i32* %8
%25 = load i32, i32* %6
%26 = call i32 @Dump3DParameters(i32 %24, i32 %25)
store i32 %26, i32* %6
%27 = load i32, i32* %8
%28 = load i32, i32* %6
%29 = call i32 @Dump3DCapabilities(i32 %27, i32 %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = call i32 @FindAndMapFifo(i64** %9, i64* %10, i32 %30)
store i32 %31, i32* %6
%32 = load i64*, i64** %9
%33 = icmp ne i64* %32, null
br i1 %33, label %34, label %42
34: ; preds = %23
%35 = load i64, i64* %10
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i64*, i64** %9
%39 = load i64, i64* %10
%40 = load i32, i32* %6
%41 = call i32 @DumpFifoStuff(i64* %38, i64 %39, i32 %40)
store i32 %41, i32* %6
br label %42
42: ; preds = %37, %34, %23
br label %48
43: ; preds = %17
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %7
%46 = load i32, i32* @errno
%47 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %45, i32 %46)
store i32 1, i32* %6
br label %48
48: ; preds = %43, %42
%49 = load i32, i32* %6
ret i32 %49
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/dri/card0\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"error opening '%s': %d\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64*
%4 = alloca i64
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
br label %9
9: ; preds = %6, %2
%10 = phi i8* [ %8, %6 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %2 ]
%11 = load i32, i32* @O_RDWR
%12 = tail call i32 @open(i8* %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %29, label %14
14: ; preds = %9
%15 = bitcast i64** %3 to i8*
store i64* null, i64** %3
%16 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%17 = tail call i32 @Dump3DParameters(i32 %12, i32 0)
%18 = tail call i32 @Dump3DCapabilities(i32 %12, i32 %17)
%19 = call i32 @FindAndMapFifo(i64** %3, i64* %4, i32 %18)
%20 = load i64*, i64** %3
%21 = icmp ne i64* %20, null
%22 = load i64, i64* %4
%23 = icmp ne i64 %22, 0
%24 = select i1 %21, i1 %23, i1 false
br i1 %24, label %25, label %27
25: ; preds = %14
%26 = call i32 @DumpFifoStuff(i64* %20, i64 %22, i32 %19)
br label %27
27: ; preds = %25, %14
%28 = phi i32 [ %26, %25 ], [ %19, %14 ]
br label %33
29: ; preds = %9
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %31)
br label %33
33: ; preds = %29, %27
%34 = phi i32 [ %28, %27 ], [ 1, %29 ]
ret i32 %34
}