#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 */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ ioctl(int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ print(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  int fd;
  if (argc != 2) {
    print(argv[0]);
    return -1;
  }
  fd = open("/dev/dma_0", O_RDWR);
  if (fd < 0) {
    printf("can't open /dev/dma\n");
    return -1;
  }
  if (strcmp(argv[1], "nodma") == 0) {
    while (1) {
      ioctl(fd, 0);
    }
  } else if (strcmp(argv[1], "dma") == 0) {
    while (1) {
      ioctl(fd, 1);
    }
  } else {
    print(argv[0]);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1188 <main+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <print@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123c <main+0xec>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c2 <main+0x72>
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123c <main+0xec>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11f4 <main+0xa4>
jmp    11e5 <main+0x95>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1040 <ioctl@plt>
jmp    11e5 <main+0x95>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1229 <main+0xd9>
jmp    1217 <main+0xc7>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1040 <ioctl@plt>
jmp    1217 <main+0xc7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <print@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edi
jne    11a1 <main+0x51>
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
lea    0xe94(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11ce <main+0x7e>
mov    %eax,%ebx
mov    0x8(%r14),%rdi
lea    0xe89(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11b0 <main+0x60>
mov    0x8(%r14),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11c0 <main+0x70>
mov    (%r14),%rdi
call   1050 <print@plt>
jmp    11da <main+0x8a>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <ioctl@plt>
jmp    11b0 <main+0x60>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    $0x1,%esi
call   1040 <ioctl@plt>
jmp    11c0 <main+0x70>
lea    0xe3c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/dma_0\00"
@O_RDWR = global i32 0
@.str.1 = [21 x i8] c"can't open /dev/dma\0A\00"
@.str.2 = [6 x i8] c"nodma\00"
@.str.3 = [4 x i8] c"dma\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @print(i8* %12)
store i32 -1, i32* %3
br label %46
14: ; preds = %2
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %46
21: ; preds = %14
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %21
br label %28
28: ; preds = %27, %28
%29 = load i32, i32* %6
%30 = call i32 @ioctl(i32 %29, i32 0)
br label %28
31: ; preds = %21
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %31
br label %38
38: ; preds = %37, %38
%39 = load i32, i32* %6
%40 = call i32 @ioctl(i32 %39, i32 1)
br label %38
41: ; preds = %31
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i32 @print(i8* %44)
store i32 -1, i32* %3
br label %46
46: ; preds = %41, %19, %9
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/dma_0\00"
@O_RDWR = global i32 0
@.str.2 = [6 x i8] c"nodma\00"
@.str.3 = [4 x i8] c"dma\00"
@str = [20 x i8] c"can't open /dev/dma\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @print(i8* %5)
br label %29
7: ; preds = %2
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %29
13: ; preds = %7
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13, %18
%19 = tail call i32 @ioctl(i32 %9, i32 0)
br label %18
20: ; preds = %13
%21 = load i8*, i8** %14
%22 = tail call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20, %24
%25 = tail call i32 @ioctl(i32 %9, i32 1)
br label %24
26: ; preds = %20
%27 = load i8*, i8** %1
%28 = tail call i32 @print(i8* %27)
br label %29
29: ; preds = %26, %11, %4
ret i32 -1
}