#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__ uint8_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ _SC_PAGESIZE;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *mmap(int /*<<< orphan*/ *, int /*<<< orphan*/, int, int /*<<< orphan*/,
           int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strtol(char *, char **, int);
int /*<<< orphan*/ sysconf(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd;
  char *end;
  volatile void *cfg;
  long number;
  errno = 0;
  number = (argc == 2) ? strtol(argv[1], &end, 10) : -1;
  if (errno != 0 || end == argv[1] || number < 0 || number > 255) {
    fprintf(stderr, "Usage: led-output [0-255]\n");
    return EXIT_FAILURE;
  }
  if ((fd = open("/dev/mem", O_RDWR)) < 0) {
    fprintf(stderr, "Cannot open /dev/mem.\n");
    return EXIT_FAILURE;
  }
  cfg = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE, MAP_SHARED,
             fd, 0x40041000);
  *(uint8_t *)(cfg + 2) = (uint8_t)number;
  return EXIT_SUCCESS;
}


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)
mov    0x2e4b(%rip),%rax
movq   $0x0,(%rax)
cmpl   $0x2,-0x8(%rbp)
jne    119c <main+0x4c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x34(%rbp)
jmp    11a9 <main+0x59>
mov    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    11a9 <main+0x59>
mov    -0x34(%rbp),%eax
cltq
mov    %rax,-0x30(%rbp)
mov    0x2dff(%rip),%rax
cmpq   $0x0,(%rax)
jne    11ee <main+0x9e>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    0x8(%rcx),%rax
je     11ee <main+0x9e>
cmpq   $0x0,-0x30(%rbp)
jl     11ee <main+0x9e>
cmpq   $0xff,-0x30(%rbp)
jle    1214 <main+0xc4>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b5 <main+0x165>
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
lea    0xdf7(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    125b <main+0x10b>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b5 <main+0x165>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %eax,%esi
mov    0x2d86(%rip),%rax
mov    (%rax),%edx
mov    0x2d2d(%rip),%rax
or     (%rax),%edx
mov    0x2d64(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x40041000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x2(%rax)
mov    0x2cf0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e59(%rip),%rbx
movq   $0x0,(%rbx)
cmp    $0x2,%edi
jne    1187 <main+0x37>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
cmpq   $0x0,(%rbx)
je     11ae <main+0x5e>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %eax,%r14d
mov    0x8(%rsp),%rax
cmp    0x8(%rbp),%rax
je     1187 <main+0x37>
test   %r14d,%r14d
js     1187 <main+0x37>
cmp    $0x100,%r14d
jge    1187 <main+0x37>
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
lea    0xe41(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1233 <main+0xe3>
mov    %eax,%ebp
movslq %r14d,%rbx
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    0x2dfb(%rip),%rcx
mov    0x2da4(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2dd9(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %ebp,%r8d
mov    $0x40041000,%r9d
call   1030 <mmap@plt>
mov    %rbx,0x2(%rax)
mov    0x2d72(%rip),%rax
jmp    11a3 <main+0x53>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
jmp    1197 <main+0x47>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [27 x i8] c"Usage: led-output [0-255]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@.str.2 = [23 x i8] c"Cannot open /dev/mem.\0A\00"
@_SC_PAGESIZE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@EXIT_SUCCESS = 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 i8*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* @errno
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @strtol(i8* %15, i8** %7, i32 10)
br label %18
17: ; preds = %2
br label %18
18: ; preds = %17, %12
%19 = phi i32 [ %16, %12 ], [ -1, %17 ]
%20 = sext i32 %19 to i64
store i64 %20, i64* %9
%21 = load i64, i64* @errno
%22 = icmp ne i64 %21, 0
br i1 %22, label %35, label %23
23: ; preds = %18
%24 = load i8*, i8** %7
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = icmp eq i8* %24, %27
br i1 %28, label %35, label %29
29: ; preds = %23
%30 = load i64, i64* %9
%31 = icmp slt i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i64, i64* %9
%34 = icmp sgt i64 %33, 255
br i1 %34, label %35, label %39
35: ; preds = %32, %29, %23, %18
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
store i32 %38, i32* %3
br label %61
39: ; preds = %32
%40 = load i32, i32* @O_RDWR
%41 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %40)
store i32 %41, i32* %6
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
store i32 %46, i32* %3
br label %61
47: ; preds = %39
%48 = load i32, i32* @_SC_PAGESIZE
%49 = call i32 @sysconf(i32 %48)
%50 = load i32, i32* @PROT_READ
%51 = load i32, i32* @PROT_WRITE
%52 = or i32 %50, %51
%53 = load i32, i32* @MAP_SHARED
%54 = load i32, i32* %6
%55 = call i8* @mmap(i32* null, i32 %49, i32 %52, i32 %53, i32 %54, i32 1074008064)
store i8* %55, i8** %8
%56 = load i64, i64* %9
%57 = load i8*, i8** %8
%58 = getelementptr i8, i8* %57, i64 2
%59 = bitcast i8* %58 to i64*
store i64 %56, i64* %59
%60 = load i32, i32* @EXIT_SUCCESS
store i32 %60, i32* %3
br label %61
61: ; preds = %47, %43, %35
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [27 x i8] c"Usage: led-output [0-255]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@.str.2 = [23 x i8] c"Cannot open /dev/mem.\0A\00"
@_SC_PAGESIZE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %22
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i32 @strtol(i8* %8, i8** %3, i32 10)
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %6
%13 = sext i32 %9 to i64
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = icmp eq i8* %14, %16
%18 = icmp slt i32 %9, 0
%19 = select i1 %17, i1 true, i1 %18
%20 = icmp sgt i32 %9, 255
%21 = select i1 %19, i1 true, i1 %20
br i1 %21, label %22, label %25
22: ; preds = %2, %12, %6
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %42
25: ; preds = %12
%26 = load i32, i32* @O_RDWR
%27 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %42
32: ; preds = %25
%33 = load i32, i32* @_SC_PAGESIZE
%34 = tail call i32 @sysconf(i32 %33)
%35 = load i32, i32* @PROT_READ
%36 = load i32, i32* @PROT_WRITE
%37 = or i32 %36, %35
%38 = load i32, i32* @MAP_SHARED
%39 = tail call i8* @mmap(i32* null, i32 %34, i32 %37, i32 %38, i32 %27, i32 1074008064)
%40 = getelementptr i8, i8* %39, i64 2
%41 = bitcast i8* %40 to i64*
store i64 %13, i64* %41
br label %42
42: ; preds = %32, %29, %22
%43 = phi i32* [ @EXIT_FAILURE, %22 ], [ @EXIT_FAILURE, %29 ], [ @EXIT_SUCCESS, %32 ]
%44 = load i32, i32* %43
ret i32 %44
}