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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_RDWR;
int O_SYNC;
int PROT_READ;
int PROT_WRITE;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int, int);
int munmap(void *, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  void *lw_bridge_map = 0;
  uint32_t *custom_led_map = 0;
  int devmem_fd = 0;
  int result = 0;
  int blink_times = 0;
  if (argc != 2) {
    printf("Please enter only one argument that specifies the number of times "
           "to blink the LEDs\n");
    exit(EXIT_FAILURE);
  }
  blink_times = atoi(argv[1]);
  devmem_fd = open("/dev/mem", O_RDWR | O_SYNC);
  if (devmem_fd < 0) {
    perror("devmem open");
    exit(EXIT_FAILURE);
  }
  lw_bridge_map = (uint32_t *)mmap(NULL, 0x0020000, PROT_READ | PROT_WRITE,
                                   MAP_SHARED, devmem_fd, 0xFF200000);
  if (lw_bridge_map == MAP_FAILED) {
    perror("devmem mmap");
    close(devmem_fd);
    exit(EXIT_FAILURE);
  }
  custom_led_map = (uint32_t *)(lw_bridge_map + 0x10008);
  printf("Blinking LEDs %d times...\n", blink_times);
  for (int i = 0; i < blink_times; ++i) {
    *custom_led_map = 0xFF;
    usleep(500000);
    *custom_led_map = 0x00;
    usleep(500000);
  }
  printf("Done!\n");
  result = munmap(lw_bridge_map, 0x0020000);
  if (result < 0) {
    perror("devmem munmap");
    close(devmem_fd);
    exit(EXIT_FAILURE);
  }
  close(devmem_fd);
  exit(EXIT_SUCCESS);
}


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)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f1 <main+0x61>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
mov    0x2dbf(%rip),%rax
or     (%rax),%esi
lea    0xe3b(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1246 <main+0xb6>
lea    0xe2b(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edx
mov    0x2d62(%rip),%rax
or     (%rax),%edx
mov    0x2d89(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x20000,%esi
mov    $0xff200000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d20(%rip),%rcx
cmp    (%rcx),%rax
jne    12b3 <main+0x123>
lea    0xdd2(%rip),%rdi
call   1080 <perror@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x10008,%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    131b <main+0x18b>
mov    -0x20(%rbp),%rax
movl   $0xff,(%rax)
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12d9 <main+0x149>
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x20000,%esi
call   1060 <munmap@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1366 <main+0x1d6>
lea    0xd4d(%rip),%rdi
call   1080 <perror@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    0x2c61(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    0x2c3b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11e7 <main+0x47>
mov    0x8(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebp
mov    0x2e1d(%rip),%rax
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe33(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
jns    11f8 <main+0x58>
lea    0xe2c(%rip),%rdi
call   1090 <perror@plt>
jmp    12be <main+0x11e>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
jmp    12be <main+0x11e>
mov    %eax,%r14d
mov    0x2df6(%rip),%rax
mov    0x2daf(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2dd4(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x20000,%esi
mov    %r14d,%r8d
mov    $0xff200000,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    0x2d73(%rip),%rax
cmp    %rbx,(%rax)
jne    1243 <main+0xa3>
lea    0xdd4(%rip),%rdi
jmp    12b1 <main+0x111>
lea    0xdd7(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebp,%ebp
jle    128d <main+0xed>
nopw   0x0(%rax,%rax,1)
movl   $0xff,0x10008(%rbx)
mov    $0x7a120,%edi
call   10c0 <usleep@plt>
movl   $0x0,0x10008(%rbx)
mov    $0x7a120,%edi
call   10c0 <usleep@plt>
add    $0xffffffff,%ebp
jne    1260 <main+0xc0>
lea    0xdb6(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x20000,%esi
call   1070 <munmap@plt>
test   %eax,%eax
jns    12cc <main+0x12c>
lea    0xd8b(%rip),%rdi
call   1090 <perror@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [85 x i8] c"Please enter only one argument that specifies the number of times to blink the LEDs\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str.2 = [12 x i8] c"devmem open\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.3 = [12 x i8] c"devmem mmap\00"
@.str.4 = [27 x i8] c"Blinking LEDs %d times...\0A\00"
@.str.5 = [7 x i8] c"Done!\0A\00"
@.str.6 = [14 x i8] c"devmem munmap\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32* null, i32** %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %10
%23 = load i32, i32* @O_RDWR
%24 = load i32, i32* @O_SYNC
%25 = or i32 %23, %24
%26 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %25)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %18
%30 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %18
%34 = load i32, i32* @PROT_READ
%35 = load i32, i32* @PROT_WRITE
%36 = or i32 %34, %35
%37 = load i32, i32* @MAP_SHARED
%38 = load i32, i32* %8
%39 = call i64 @mmap(i32* null, i32 131072, i32 %36, i32 %37, i32 %38, i32 -14680064)
%40 = inttoptr i64 %39 to i32*
%41 = bitcast i32* %40 to i8*
store i8* %41, i8** %6
%42 = load i8*, i8** %6
%43 = load i8*, i8** @MAP_FAILED
%44 = icmp eq i8* %42, %43
br i1 %44, label %45, label %51
45: ; preds = %33
%46 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* %8
%48 = call i32 @close(i32 %47)
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %33
%52 = load i8*, i8** %6
%53 = getelementptr i8, i8* %52, i64 65544
%54 = bitcast i8* %53 to i32*
store i32* %54, i32** %7
%55 = load i32, i32* %10
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %55)
store i32 0, i32* %11
br label %57
57: ; preds = %66, %51
%58 = load i32, i32* %11
%59 = load i32, i32* %10
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %69
61: ; preds = %57
%62 = load i32*, i32** %7
store i32 255, i32* %62
%63 = call i32 @usleep(i32 500000)
%64 = load i32*, i32** %7
store i32 0, i32* %64
%65 = call i32 @usleep(i32 500000)
br label %66
66: ; preds = %61
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %57
69: ; preds = %57
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%71 = load i8*, i8** %6
%72 = call i32 @munmap(i8* %71, i32 131072)
store i32 %72, i32* %9
%73 = load i32, i32* %9
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %81
75: ; preds = %69
%76 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%77 = load i32, i32* %8
%78 = call i32 @close(i32 %77)
%79 = load i32, i32* @EXIT_FAILURE
%80 = call i32 @exit(i32 %79)
unreachable
81: ; preds = %69
%82 = load i32, i32* %8
%83 = call i32 @close(i32 %82)
%84 = load i32, i32* @EXIT_SUCCESS
%85 = call i32 @exit(i32 %84)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str.2 = [12 x i8] c"devmem open\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.3 = [12 x i8] c"devmem mmap\00"
@.str.4 = [27 x i8] c"Blinking LEDs %d times...\0A\00"
@.str.6 = [14 x i8] c"devmem munmap\00"
@EXIT_SUCCESS = global i32 0
@str = [6 x i8] c"Done!\00"
@str.7 = [84 x i8] c"Please enter only one argument that specifies the number of times to blink the LEDs\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([84 x i8], [84 x i8]* @str.7, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_SYNC
%14 = or i32 %13, %12
%15 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %8
%18 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %8
%22 = load i32, i32* @PROT_READ
%23 = load i32, i32* @PROT_WRITE
%24 = or i32 %23, %22
%25 = load i32, i32* @MAP_SHARED
%26 = tail call i64 @mmap(i32* null, i32 131072, i32 %24, i32 %25, i32 %15, i32 -14680064)
%27 = inttoptr i64 %26 to i8*
%28 = load i8*, i8** @MAP_FAILED
%29 = icmp eq i8* %28, %27
br i1 %29, label %30, label %35
30: ; preds = %21
%31 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%32 = tail call i32 @close(i32 %15)
%33 = load i32, i32* @EXIT_FAILURE
%34 = tail call i32 @exit(i32 %33)
unreachable
35: ; preds = %21
%36 = getelementptr i8, i8* %27, i64 65544
%37 = bitcast i8* %36 to i32*
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%39 = icmp sgt i32 %11, 0
br i1 %39, label %44, label %40
40: ; preds = %44, %35
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%42 = tail call i32 @munmap(i8* %27, i32 131072)
%43 = icmp slt i32 %42, 0
br i1 %43, label %50, label %55
44: ; preds = %35, %44
%45 = phi i32 [ %48, %44 ], [ 0, %35 ]
store i32 255, i32* %37
%46 = tail call i32 @usleep(i32 500000)
store i32 0, i32* %37
%47 = tail call i32 @usleep(i32 500000)
%48 = add nuw nsw i32 %45, 1
%49 = icmp eq i32 %48, %11
br i1 %49, label %40, label %44
50: ; preds = %40
%51 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%52 = tail call i32 @close(i32 %15)
%53 = load i32, i32* @EXIT_FAILURE
%54 = tail call i32 @exit(i32 %53)
unreachable
55: ; preds = %40
%56 = tail call i32 @close(i32 %15)
%57 = load i32, i32* @EXIT_SUCCESS
%58 = tail call i32 @exit(i32 %57)
unreachable
}