#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 int __u32;

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
unsigned char *mmap(int /*<<< orphan*/, int, int, int /*<<< orphan*/, int,
                    int /*<<< orphan*/);
int /*<<< orphan*/ munmap(unsigned char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strncmp(char *, char *, int);
int strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  int memfd, i;
  __u32 addr = 0;
  __u32 len = 0x01000000;
  unsigned char *memspace;
  __u32 *lmspace;
  if (argc > 3 || (argc >= 2 && !strncmp(argv[1], "--help", 6))) {
    printf("Sets all alpha values for pixels when in 32-bit mode to full "
           "opacity.\n");
    printf("Usage: %s [addr [len]]\n", argv[0]);
    return -1;
  }
  if (argc >= 2) {
    addr = strtoul(argv[1], NULL, 16);
  }
  if (argc >= 3) {
    len = strtoul(argv[2], NULL, 16);
  }
  addr &= 0xfffffffc;
  len &= 0xfffffffc;
  if (addr >= 0x01000000) {
    addr = 0;
  }
  if (addr + len >= 0x01000000) {
    len = 0x01000000 - addr;
  }
  if ((memfd = open("/dev/tl880/mem0", O_RDWR)) < 0) {
    perror("Unable to open /dev/tl880/mem0");
    return -1;
  }
  printf("Mapping memory space\n");
  if (!(memspace = mmap(0, 0x01000000, PROT_READ | PROT_WRITE, MAP_SHARED,
                        memfd, 0))) {
    perror("Failed to mmap region 1 (mem)");
    close(memfd);
    return -1;
  }
  lmspace = (__u32 *)memspace;
  printf("Writing alpha values\n");
  for (i = addr; i < addr + len; i += 4) {
    memspace[i + 3] = 0xff;
  }
  printf("Unmapping memory space\n");
  munmap(memspace, 0x01000000);
  close(memfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1000000,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
jg     11da <main+0x5a>
cmpl   $0x2,-0x8(%rbp)
jl     1209 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe39(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1209 <main+0x89>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ac <main+0x22c>
cmpl   $0x2,-0x8(%rbp)
jl     122c <main+0xac>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     124f <main+0xcf>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xfffffffc,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
and    $0xfffffffc,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x1000000,-0x1c(%rbp)
jl     1275 <main+0xf5>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
cmp    $0x1000000,%eax
jl     1291 <main+0x111>
mov    $0x1000000,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
lea    0xdd4(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    12ca <main+0x14a>
lea    0xdad(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ac <main+0x22c>
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%edx
mov    0x2ce0(%rip),%rax
or     (%rax),%edx
mov    0x2cf7(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x1000000,%esi
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1335 <main+0x1b5>
lea    0xd7f(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ac <main+0x22c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
cmp    %ecx,%eax
jge    1381 <main+0x201>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movb   $0xff,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x18(%rbp)
jmp    1351 <main+0x1d1>
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1000000,%esi
call   1070 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
cmp    $0x3,%edi
jle    11c7 <main+0x37>
lea    0xef6(%rip),%rdi
call   1040 <puts@plt>
mov    (%r15),%rsi
lea    0xe51(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%eax
jmp    12fa <main+0x16a>
mov    %edi,%ebp
xor    %ebx,%ebx
mov    $0x1000000,%r12d
mov    $0x1000000,%eax
cmp    $0x2,%edi
jl     1235 <main+0xa5>
mov    0x8(%r15),%rdi
lea    0xe1a(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11a0 <main+0x10>
mov    0x8(%r15),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
mov    %eax,%r14d
and    $0xfffffffc,%r14d
mov    $0x1000000,%eax
cmp    $0x3,%ebp
jb     122a <main+0x9a>
mov    0x10(%r15),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
and    $0xfffffffc,%eax
cmp    $0x1000000,%r14d
cmovl  %r14d,%ebx
lea    (%rbx,%rax,1),%ecx
sub    %ebx,%r12d
cmp    $0x1000000,%ecx
cmovl  %eax,%r12d
mov    0x2d8c(%rip),%rax
mov    (%rax),%esi
lea    0xdd9(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1303 <main+0x173>
mov    %eax,%r14d
lea    0xdf0(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d80(%rip),%rax
mov    0x2d49(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d5e(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x1000000,%esi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
test   %rax,%rax
je     1316 <main+0x186>
mov    %rax,%rbp
lea    0xdc4(%rip),%rdi
call   1040 <puts@plt>
test   %r12d,%r12d
jle    12d7 <main+0x147>
add    %ebx,%r12d
nopw   0x0(%rax,%rax,1)
movslq %ebx,%rbx
mov    %rbx,%rax
or     $0x3,%rax
movb   $0xff,0x0(%rbp,%rax,1)
add    $0x4,%ebx
cmp    %r12d,%ebx
jl     12c0 <main+0x130>
lea    0xda8(%rip),%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
mov    $0x1000000,%esi
call   1080 <munmap@plt>
mov    %r14d,%edi
call   1070 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd15(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%eax
jmp    12fa <main+0x16a>
lea    0xd21(%rip),%rdi
call   10a0 <perror@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    $0xffffffff,%eax
jmp    12fa <main+0x16a>

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@.str.1 = [71 x i8] c"Sets all alpha values for pixels when in 32-bit mode to full opacity.\0A\00"
@.str.2 = [24 x i8] c"Usage: %s [addr [len]]\0A\00"
@.str.3 = [16 x i8] c"/dev/tl880/mem0\00"
@O_RDWR = global i32 0
@.str.4 = [31 x i8] c"Unable to open /dev/tl880/mem0\00"
@.str.5 = [22 x i8] c"Mapping memory space\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.6 = [30 x i8] c"Failed to mmap region 1 (mem)\00"
@.str.7 = [22 x i8] c"Writing alpha values\0A\00"
@.str.8 = [24 x i8] c"Unmapping memory space\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 16777216, i32* %9
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 3
br i1 %13, label %23, label %14
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp sge i32 %15, 2
br i1 %16, label %17, label %29
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strncmp(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%22 = icmp ne i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %17, %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %27)
store i32 -1, i32* %3
br label %106
29: ; preds = %17, %14
%30 = load i32, i32* %4
%31 = icmp sge i32 %30, 2
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @strtoul(i8* %35, i32* null, i32 16)
store i32 %36, i32* %8
br label %37
37: ; preds = %32, %29
%38 = load i32, i32* %4
%39 = icmp sge i32 %38, 3
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i32 @strtoul(i8* %43, i32* null, i32 16)
store i32 %44, i32* %9
br label %45
45: ; preds = %40, %37
%46 = load i32, i32* %8
%47 = and i32 %46, -4
store i32 %47, i32* %8
%48 = load i32, i32* %9
%49 = and i32 %48, -4
store i32 %49, i32* %9
%50 = load i32, i32* %8
%51 = icmp sge i32 %50, 16777216
br i1 %51, label %52, label %53
52: ; preds = %45
store i32 0, i32* %8
br label %53
53: ; preds = %52, %45
%54 = load i32, i32* %8
%55 = load i32, i32* %9
%56 = add nsw i32 %54, %55
%57 = icmp sge i32 %56, 16777216
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = load i32, i32* %8
%60 = sub nsw i32 16777216, %59
store i32 %60, i32* %9
br label %61
61: ; preds = %58, %53
%62 = load i32, i32* @O_RDWR
%63 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %62)
store i32 %63, i32* %6
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %61
%66 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %106
67: ; preds = %61
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%69 = load i32, i32* @PROT_READ
%70 = load i32, i32* @PROT_WRITE
%71 = or i32 %69, %70
%72 = load i32, i32* @MAP_SHARED
%73 = load i32, i32* %6
%74 = call i8* @mmap(i32 0, i32 16777216, i32 %71, i32 %72, i32 %73, i32 0)
store i8* %74, i8** %10
%75 = icmp ne i8* %74, null
br i1 %75, label %80, label %76
76: ; preds = %67
%77 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%78 = load i32, i32* %6
%79 = call i32 @close(i32 %78)
store i32 -1, i32* %3
br label %106
80: ; preds = %67
%81 = load i8*, i8** %10
%82 = bitcast i8* %81 to i32*
store i32* %82, i32** %11
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%84 = load i32, i32* %8
store i32 %84, i32* %7
br label %85
85: ; preds = %97, %80
%86 = load i32, i32* %7
%87 = load i32, i32* %8
%88 = load i32, i32* %9
%89 = add nsw i32 %87, %88
%90 = icmp slt i32 %86, %89
br i1 %90, label %91, label %100
91: ; preds = %85
%92 = load i8*, i8** %10
%93 = load i32, i32* %7
%94 = add nsw i32 %93, 3
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8, i8* %92, i64 %95
store i8 -1, i8* %96
br label %97
97: ; preds = %91
%98 = load i32, i32* %7
%99 = add nsw i32 %98, 4
store i32 %99, i32* %7
br label %85
100: ; preds = %85
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%102 = load i8*, i8** %10
%103 = call i32 @munmap(i8* %102, i32 16777216)
%104 = load i32, i32* %6
%105 = call i32 @close(i32 %104)
store i32 0, i32* %3
br label %106
106: ; preds = %100, %76, %65, %23
%107 = load i32, i32* %3
ret i32 %107
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@.str.2 = [24 x i8] c"Usage: %s [addr [len]]\0A\00"
@.str.3 = [16 x i8] c"/dev/tl880/mem0\00"
@O_RDWR = global i32 0
@.str.4 = [31 x i8] c"Unable to open /dev/tl880/mem0\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.6 = [30 x i8] c"Failed to mmap region 1 (mem)\00"
@str = [21 x i8] c"Mapping memory space\00"
@str.9 = [21 x i8] c"Writing alpha values\00"
@str.10 = [23 x i8] c"Unmapping memory space\00"
@str.11 = [70 x i8] c"Sets all alpha values for pixels when in 32-bit mode to full opacity.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 3
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %29
6: ; preds = %4
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strncmp(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %6, %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.11, i64 0, i64 0))
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %67
15: ; preds = %6
%16 = load i8*, i8** %7
%17 = tail call i32 @strtoul(i8* nocapture %16, i32* null, i32 16)
%18 = and i32 %17, -4
%19 = icmp ugt i32 %0, 2
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32 @strtoul(i8* nocapture %22, i32* null, i32 16)
%24 = and i32 %23, -4
br label %25
25: ; preds = %20, %15
%26 = phi i32 [ %24, %20 ], [ 16777216, %15 ]
%27 = icmp sgt i32 %18, 16777215
%28 = select i1 %27, i32 0, i32 %18
br label %29
29: ; preds = %25, %4
%30 = phi i32 [ 16777216, %4 ], [ %26, %25 ]
%31 = phi i32 [ 0, %4 ], [ %28, %25 ]
%32 = add nsw i32 %31, %30
%33 = icmp sgt i32 %32, 16777215
%34 = sub nsw i32 16777216, %31
%35 = select i1 %33, i32 %34, i32 %30
%36 = load i32, i32* @O_RDWR
%37 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %29
%40 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %67
41: ; preds = %29
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%43 = load i32, i32* @PROT_READ
%44 = load i32, i32* @PROT_WRITE
%45 = or i32 %44, %43
%46 = load i32, i32* @MAP_SHARED
%47 = tail call i8* @mmap(i32 0, i32 16777216, i32 %45, i32 %46, i32 %37, i32 0)
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %52
49: ; preds = %41
%50 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%51 = tail call i32 @close(i32 %37)
br label %67
52: ; preds = %41
%53 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0))
%54 = add nsw i32 %35, %31
%55 = icmp sgt i32 %35, 0
br i1 %55, label %56, label %63
56: ; preds = %52, %56
%57 = phi i32 [ %61, %56 ], [ %31, %52 ]
%58 = or i32 %57, 3
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %47, i64 %59
store i8 -1, i8* %60
%61 = add nsw i32 %57, 4
%62 = icmp slt i32 %61, %54
br i1 %62, label %56, label %63
63: ; preds = %56, %52
%64 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.10, i64 0, i64 0))
%65 = tail call i32 @munmap(i8* %47, i32 16777216)
%66 = tail call i32 @close(i32 %37)
br label %67
67: ; preds = %63, %49, %39, %11
%68 = phi i32 [ -1, %11 ], [ -1, %39 ], [ 0, %63 ], [ -1, %49 ]
ret i32 %68
}