#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 /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ do_tests(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, int, int, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  FILE *infile;
  FILE *dev_node;
  char filename[] = "out.dat";
  char devnode[] = "/dev/pwm_dma";
  uint32_t *buffer = NULL;
  uint32_t *bufptr = NULL;
  dev_node = fopen(devnode, "w");
  if (!dev_node) {
    printf("Can't open /dev/pwm_dma. Check that it exists.\n");
    return -1;
  }
  do_tests(devnode);
  infile = fopen(filename, "r");
  if (!infile) {
    printf("Can't open input file.\n");
    fclose(dev_node);
    return -1;
  }
  buffer = (uint32_t *)malloc(0x08000000);
  if (!buffer) {
    printf("Can't allocate memory\n");
    return -1;
  }
  bufptr = buffer;
  fread(buffer, sizeof(uint32_t), 0x08000000 / 4, infile);
  fwrite(buffer, sizeof(uint32_t), 0x08000000 / 4, devnode);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe73(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe70(%rip),%rax
mov    %rax,-0x35(%rbp)
mov    0xe6e(%rip),%eax
mov    %eax,-0x2d(%rbp)
mov    0xe69(%rip),%al
mov    %al,-0x29(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
lea    -0x35(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f5 <main+0x85>
lea    0xe33(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ac <main+0x13c>
lea    -0x35(%rbp),%rdi
call   1080 <do_tests@plt>
lea    -0x28(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    123e <main+0xce>
lea    0xe25(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ac <main+0x13c>
mov    $0x8000000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    126f <main+0xff>
lea    0xe03(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ac <main+0x13c>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x2000000,%edx
call   1030 <fread@plt>
mov    -0x40(%rbp),%rdi
lea    -0x35(%rbp),%rcx
mov    $0x4,%esi
mov    $0x2000000,%edx
call   1090 <fwrite@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movabs $0x7461642e74756f,%rax
mov    %rax,0x10(%rsp)
movabs $0x616d645f6d7770,%rax
mov    %rax,0x5(%rsp)
movabs $0x6d77702f7665642f,%rax
70 77 6d
mov    %rax,(%rsp)
lea    0xe63(%rip),%rsi
mov    %rsp,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     121b <main+0xab>
mov    %rax,%rbx
mov    %rsp,%rdi
call   1080 <do_tests@plt>
lea    0xe46(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1224 <main+0xb4>
mov    %rax,%r14
mov    $0x8000000,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     123a <main+0xca>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x4,%esi
mov    $0x2000000,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x2000000,%edx
call   1090 <fwrite@plt>
xor    %eax,%eax
jmp    124b <main+0xdb>
lea    0xdef(%rip),%rdi
jmp    1241 <main+0xd1>
lea    0xe15(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1246 <main+0xd6>
lea    0xe16(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.filename = [8 x i8] c"out.dat\00"
@__const.main.devnode = [13 x i8] c"/dev/pwm_dma\00"
@.str = [2 x i8] c"w\00"
@.str.1 = [48 x i8] c"Can't open /dev/pwm_dma. Check that it exists.\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [24 x i8] c"Can't open input file.\0A\00"
@.str.4 = [23 x i8] c"Can't allocate memory\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 [8 x i8]
%9 = alloca [13 x i8]
%10 = alloca i32*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [8 x i8]* %8 to i8*
%13 = bitcast [13 x i8]* %9 to i8*
store i32* null, i32** %10
store i32* null, i32** %11
%14 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 0
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %7
%16 = load i32*, i32** %7
%17 = icmp ne i32* %16, null
br i1 %17, label %20, label %18
18: ; preds = %2
%19 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %46
20: ; preds = %2
%21 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 0
%22 = call i32 @do_tests(i8* %21)
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp ne i32* %25, null
br i1 %26, label %31, label %27
27: ; preds = %20
%28 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32*, i32** %7
%30 = call i32 @fclose(i32* %29)
store i32 -1, i32* %3
br label %46
31: ; preds = %20
%32 = call i64 @malloc(i32 134217728)
%33 = inttoptr i64 %32 to i32*
store i32* %33, i32** %10
%34 = load i32*, i32** %10
%35 = icmp ne i32* %34, null
br i1 %35, label %38, label %36
36: ; preds = %31
%37 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %46
38: ; preds = %31
%39 = load i32*, i32** %10
store i32* %39, i32** %11
%40 = load i32*, i32** %10
%41 = load i32*, i32** %6
%42 = call i32 @fread(i32* %40, i32 4, i32 33554432, i32* %41)
%43 = load i32*, i32** %10
%44 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 0
%45 = call i32 @fwrite(i32* %43, i32 4, i32 33554432, i8* %44)
store i32 0, i32* %3
br label %46
46: ; preds = %38, %36, %27, %18
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@__const.main.devnode = [13 x i8] c"/dev/pwm_dma\00"
@.str = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"r\00"
@str = [47 x i8] c"Can't open /dev/pwm_dma. Check that it exists.\00"
@str.5 = [23 x i8] c"Can't open input file.\00"
@str.6 = [22 x i8] c"Can't allocate memory\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca [13 x i8]
%5 = bitcast i64* %3 to i8*
store i64 32758180202444143, i64* %3
%6 = getelementptr inbounds [13 x i8], [13 x i8]* %4, i64 0, i64 0
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
br label %27
11: ; preds = %2
%12 = call i32 @do_tests(i8* %6)
%13 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
%17 = call i32 @fclose(i32* %7)
br label %27
18: ; preds = %11
%19 = call i64 @malloc(i32 134217728)
%20 = inttoptr i64 %19 to i32*
%21 = icmp eq i64 %19, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
br label %27
24: ; preds = %18
%25 = call i32 @fread(i32* %20, i32 4, i32 33554432, i32* %13)
%26 = call i32 @fwrite(i32* %20, i32 4, i32 33554432, i8* %6)
br label %27
27: ; preds = %24, %22, %15, %9
%28 = phi i32 [ 0, %24 ], [ -1, %22 ], [ -1, %15 ], [ -1, %9 ]
ret i32 %28
}