#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 */
scalar_t__ 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 errno;
int getpagesize();
scalar_t__ mmap(int /*<<< orphan*/, int, int, int /*<<< orphan*/, int,
                unsigned int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  int fd;
  int page_size = getpagesize();
  unsigned int *mem_addr = NULL;
  unsigned int mem_phys = 0x72A00000;
  volatile unsigned int *pwm_A;
  volatile unsigned int *pwm_B;
  volatile unsigned int *pwm_C;
  volatile unsigned int *pwm_D;
  volatile unsigned int *pwm_reset_n;
  volatile unsigned int *pwm_A_enable;
  volatile unsigned int *pwm_B_enable;
  volatile unsigned int *pwm_C_enable;
  volatile unsigned int *pwm_D_enable;
  if (argc < 2) {
    printf("Error: No Value, Enter a PWM value\n");
    return 0;
  }
  fd = open("/dev/mem", O_RDWR | O_SYNC);
  if (fd < 0) {
    printf("Open /dev/mem failed - %s %d\n", strerror(errno), errno);
    return -1;
  }
  mem_addr = (unsigned int *)mmap(0, page_size, PROT_READ | PROT_WRITE,
                                  MAP_SHARED, fd, mem_phys);
  if (mem_addr == (unsigned int *)MAP_FAILED) {
    printf("Error: mmap failed\n");
    close(fd);
    return -1;
  }
  printf("%x: %x \n", (int)mem_addr, *(mem_addr));
  pwm_A = mem_addr + 0x06;
  pwm_B = mem_addr + 0x07;
  pwm_C = mem_addr + 0x08;
  pwm_D = mem_addr + 0x09;
  pwm_reset_n = mem_addr + 0x0E;
  pwm_A_enable = mem_addr + 0x0A;
  pwm_B_enable = mem_addr + 0x0B;
  pwm_C_enable = mem_addr + 0x0C;
  pwm_D_enable = mem_addr + 0x0D;
  *pwm_A_enable = 0x1;
  *pwm_B_enable = 0x1;
  *pwm_C_enable = 0x1;
  *pwm_D_enable = 0x1;
  printf("Writing PWM Value 0x%x to header pin 1\n", atoi(argv[1]));
  *pwm_A = atoi(argv[1]);
  *pwm_B = atoi(argv[1]);
  *pwm_C = atoi(argv[1]);
  *pwm_D = atoi(argv[1]);
  usleep(500000);
  *pwm_A_enable = 0x0;
  *pwm_B_enable = 0x0;
  *pwm_C_enable = 0x0;
  *pwm_D_enable = 0x0;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <getpagesize@plt>
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x72a00000,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d3 <main+0x53>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f4 <main+0x274>
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    0x2ded(%rip),%rax
or     (%rax),%esi
lea    0xe38(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1232 <main+0xb2>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f4 <main+0x274>
mov    -0x18(%rbp),%esi
mov    0x2dbc(%rip),%rax
mov    (%rax),%edx
mov    0x2d73(%rip),%rax
or     (%rax),%edx
mov    0x2d9a(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x24(%rbp),%r9d
xor    %edi,%edi
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2d42(%rip),%rcx
mov    (%rcx),%rcx
cmp    %rcx,%rax
jne    129c <main+0x11c>
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f4 <main+0x274>
mov    -0x20(%rbp),%rax
mov    %eax,%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1c,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
add    $0x24,%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
add    $0x38,%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
add    $0x28,%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
add    $0x2c,%rax
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rax
add    $0x34,%rax
mov    %rax,-0x70(%rbp)
mov    -0x58(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x60(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x68(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x70(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,%esi
lea    0xd08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
mov    -0x58(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x60(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x68(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x70(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
xor    %r15d,%r15d
xor    %eax,%eax
call   1090 <getpagesize@plt>
cmp    $0x1,%ebp
jg     11bc <main+0x2c>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
jmp    1304 <main+0x174>
mov    %eax,%ebx
mov    0x2e13(%rip),%rax
mov    0x2e04(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe29(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     12c8 <main+0x138>
mov    %eax,%ebp
mov    0x2e0b(%rip),%rax
mov    0x2dc4(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2de9(%rip),%rax
mov    (%rax),%ecx
xor    %r15d,%r15d
xor    %edi,%edi
mov    %ebx,%esi
mov    %ebp,%r8d
mov    $0x72a00000,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    0x2d90(%rip),%rax
cmp    (%rax),%rbx
je     12eb <main+0x15b>
mov    (%rbx),%edx
lea    0xdf5(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x1,0x28(%rbx)
movl   $0x1,0x2c(%rbx)
movl   $0x1,0x30(%rbx)
movl   $0x1,0x34(%rbx)
mov    0x8(%r14),%rdi
call   1080 <atoi@plt>
lea    0xdc9(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r14),%rbp
mov    %rbp,%rdi
call   1080 <atoi@plt>
mov    %eax,0x18(%rbx)
mov    %rbp,%rdi
call   1080 <atoi@plt>
mov    %eax,0x1c(%rbx)
mov    %rbp,%rdi
call   1080 <atoi@plt>
mov    %eax,0x20(%rbx)
mov    %rbp,%rdi
call   1080 <atoi@plt>
mov    %eax,0x24(%rbx)
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
movl   $0x0,0x28(%rbx)
movl   $0x0,0x2c(%rbx)
movl   $0x0,0x30(%rbx)
movl   $0x0,0x34(%rbx)
jmp    1304 <main+0x174>
mov    0x2cf1(%rip),%rbx
mov    (%rbx),%edi
call   10a0 <strerror@plt>
mov    (%rbx),%edx
lea    0xd2a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12fe <main+0x16e>
lea    0xd66(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Error: No Value, Enter a PWM value\0A\00"
@.str.1 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str.2 = [30 x i8] c"Open /dev/mem failed - %s %d\0A\00"
@errno = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i64 0
@.str.3 = [20 x i8] c"Error: mmap failed\0A\00"
@.str.4 = [9 x i8] c"%x: %x \0A\00"
@.str.5 = [40 x i8] c"Writing PWM Value 0x%x to header pin 1\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 i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = call i32 (...) @getpagesize()
store i32 %19, i32* %7
store i32* null, i32** %8
store i32 1923088384, i32* %9
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 2
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %112
24: ; preds = %2
%25 = load i32, i32* @O_RDWR
%26 = load i32, i32* @O_SYNC
%27 = or i32 %25, %26
%28 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %24
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = load i32, i32* @errno
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %33, i32 %34)
store i32 -1, i32* %3
br label %112
36: ; preds = %24
%37 = load i32, i32* %7
%38 = load i32, i32* @PROT_READ
%39 = load i32, i32* @PROT_WRITE
%40 = or i32 %38, %39
%41 = load i32, i32* @MAP_SHARED
%42 = load i32, i32* %6
%43 = load i32, i32* %9
%44 = call i64 @mmap(i32 0, i32 %37, i32 %40, i32 %41, i32 %42, i32 %43)
%45 = inttoptr i64 %44 to i32*
store i32* %45, i32** %8
%46 = load i32*, i32** %8
%47 = load i64, i64* @MAP_FAILED
%48 = inttoptr i64 %47 to i32*
%49 = icmp eq i32* %46, %48
br i1 %49, label %50, label %54
50: ; preds = %36
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%52 = load i32, i32* %6
%53 = call i32 @close(i32 %52)
store i32 -1, i32* %3
br label %112
54: ; preds = %36
%55 = load i32*, i32** %8
%56 = ptrtoint i32* %55 to i32
%57 = load i32*, i32** %8
%58 = load i32, i32* %57
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %56, i32 %58)
%60 = load i32*, i32** %8
%61 = getelementptr inbounds i32, i32* %60, i64 6
store i32* %61, i32** %10
%62 = load i32*, i32** %8
%63 = getelementptr inbounds i32, i32* %62, i64 7
store i32* %63, i32** %11
%64 = load i32*, i32** %8
%65 = getelementptr inbounds i32, i32* %64, i64 8
store i32* %65, i32** %12
%66 = load i32*, i32** %8
%67 = getelementptr inbounds i32, i32* %66, i64 9
store i32* %67, i32** %13
%68 = load i32*, i32** %8
%69 = getelementptr inbounds i32, i32* %68, i64 14
store i32* %69, i32** %14
%70 = load i32*, i32** %8
%71 = getelementptr inbounds i32, i32* %70, i64 10
store i32* %71, i32** %15
%72 = load i32*, i32** %8
%73 = getelementptr inbounds i32, i32* %72, i64 11
store i32* %73, i32** %16
%74 = load i32*, i32** %8
%75 = getelementptr inbounds i32, i32* %74, i64 12
store i32* %75, i32** %17
%76 = load i32*, i32** %8
%77 = getelementptr inbounds i32, i32* %76, i64 13
store i32* %77, i32** %18
%78 = load i32*, i32** %15
store volatile i32 1, i32* %78
%79 = load i32*, i32** %16
store volatile i32 1, i32* %79
%80 = load i32*, i32** %17
store volatile i32 1, i32* %80
%81 = load i32*, i32** %18
store volatile i32 1, i32* %81
%82 = load i8**, i8*** %5
%83 = getelementptr inbounds i8*, i8** %82, i64 1
%84 = load i8*, i8** %83
%85 = call i32 @atoi(i8* %84)
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %85)
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 1
%89 = load i8*, i8** %88
%90 = call i32 @atoi(i8* %89)
%91 = load i32*, i32** %10
store volatile i32 %90, i32* %91
%92 = load i8**, i8*** %5
%93 = getelementptr inbounds i8*, i8** %92, i64 1
%94 = load i8*, i8** %93
%95 = call i32 @atoi(i8* %94)
%96 = load i32*, i32** %11
store volatile i32 %95, i32* %96
%97 = load i8**, i8*** %5
%98 = getelementptr inbounds i8*, i8** %97, i64 1
%99 = load i8*, i8** %98
%100 = call i32 @atoi(i8* %99)
%101 = load i32*, i32** %12
store volatile i32 %100, i32* %101
%102 = load i8**, i8*** %5
%103 = getelementptr inbounds i8*, i8** %102, i64 1
%104 = load i8*, i8** %103
%105 = call i32 @atoi(i8* %104)
%106 = load i32*, i32** %13
store volatile i32 %105, i32* %106
%107 = call i32 @usleep(i32 500000)
%108 = load i32*, i32** %15
store volatile i32 0, i32* %108
%109 = load i32*, i32** %16
store volatile i32 0, i32* %109
%110 = load i32*, i32** %17
store volatile i32 0, i32* %110
%111 = load i32*, i32** %18
store volatile i32 0, i32* %111
store i32 0, i32* %3
br label %112
112: ; preds = %54, %50, %31, %22
%113 = load i32, i32* %3
ret i32 %113
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str.2 = [30 x i8] c"Open /dev/mem failed - %s %d\0A\00"
@errno = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i64 0
@.str.4 = [9 x i8] c"%x: %x \0A\00"
@.str.5 = [40 x i8] c"Writing PWM Value 0x%x to header pin 1\0A\00"
@str = [19 x i8] c"Error: mmap failed\00"
@str.6 = [35 x i8] c"Error: No Value, Enter a PWM value\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @getpagesize()
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.6, i64 0, i64 0))
br label %53
7: ; preds = %2
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_SYNC
%10 = or i32 %9, %8
%11 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %7
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = load i32, i32* @errno
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %15, i32 %16)
br label %53
18: ; preds = %7
%19 = load i32, i32* @PROT_READ
%20 = load i32, i32* @PROT_WRITE
%21 = or i32 %20, %19
%22 = load i32, i32* @MAP_SHARED
%23 = tail call i64 @mmap(i32 0, i32 %3, i32 %21, i32 %22, i32 %11, i32 1923088384)
%24 = inttoptr i64 %23 to i32*
%25 = load i64, i64* @MAP_FAILED
%26 = inttoptr i64 %25 to i32*
%27 = icmp eq i32* %24, %26
br i1 %27, label %28, label %31
28: ; preds = %18
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%30 = tail call i32 @close(i32 %11)
br label %53
31: ; preds = %18
%32 = trunc i64 %23 to i32
%33 = load i32, i32* %24
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %32, i32 %33)
%35 = getelementptr inbounds i32, i32* %24, i64 6
%36 = getelementptr inbounds i32, i32* %24, i64 7
%37 = getelementptr inbounds i32, i32* %24, i64 8
%38 = getelementptr inbounds i32, i32* %24, i64 9
%39 = getelementptr inbounds i32, i32* %24, i64 10
%40 = getelementptr inbounds i32, i32* %24, i64 11
%41 = getelementptr inbounds i32, i32* %24, i64 12
%42 = getelementptr inbounds i32, i32* %24, i64 13
store volatile i32 1, i32* %39
store volatile i32 1, i32* %40
store volatile i32 1, i32* %41
store volatile i32 1, i32* %42
%43 = getelementptr inbounds i8*, i8** %1, i64 1
%44 = load i8*, i8** %43
%45 = tail call i32 @atoi(i8* %44)
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %45)
%47 = load i8*, i8** %43
%48 = tail call i32 @atoi(i8* %47)
store volatile i32 %48, i32* %35
%49 = tail call i32 @atoi(i8* %47)
store volatile i32 %49, i32* %36
%50 = tail call i32 @atoi(i8* %47)
store volatile i32 %50, i32* %37
%51 = tail call i32 @atoi(i8* %47)
store volatile i32 %51, i32* %38
%52 = tail call i32 @usleep(i32 500000)
store volatile i32 0, i32* %39
store volatile i32 0, i32* %40
store volatile i32 0, i32* %41
store volatile i32 0, i32* %42
br label %53
53: ; preds = %31, %28, %13, %5
%54 = phi i32 [ 0, %5 ], [ -1, %13 ], [ -1, %28 ], [ 0, %31 ]
ret i32 %54
}