#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_WRONLY;
int delta_volume(int, int, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int get_volume(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int set_volume(int, int, char **);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    fprintf(stderr, "Usage: <dsp> <get|set|delta> <vol (0-100)>\n");
    return 1;
  }
  int fd = open(argv[1], O_WRONLY);
  if (fd < 0) {
    perror("open");
    return 1;
  }
  if (strcmp(argv[2], "get") == 0)
    return get_volume(fd);
  else if (strcmp(argv[2], "set") == 0)
    return set_volume(fd, argc, argv);
  else if (strcmp(argv[2], "delta") == 0)
    return delta_volume(fd, argc, argv);
  else {
    fprintf(stderr, "Invalid command \"%s\", needs \"get\" or \"set\" ...\n",
            argv[2]);
    return 1;
  }
}


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   $0x3,-0x8(%rbp)
jge    11b3 <main+0x43>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ac <main+0x13c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ee <main+0x7e>
lea    0xe4f(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ac <main+0x13c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe34(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    121c <main+0xac>
mov    -0x14(%rbp),%edi
call   1040 <get_volume@plt>
mov    %eax,-0x4(%rbp)
jmp    12ac <main+0x13c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe0a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1251 <main+0xe1>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <set_volume@plt>
mov    %eax,-0x4(%rbp)
jmp    12ac <main+0x13c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdd9(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1286 <main+0x116>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1090 <delta_volume@plt>
mov    %eax,-0x4(%rbp)
jmp    12ac <main+0x13c>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xda1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jg     119a <main+0x2a>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     1249 <main+0xd9>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
lea    0xe6a(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     121b <main+0xab>
mov    0x10(%rbx),%rdi
lea    0xe59(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1227 <main+0xb7>
mov    0x10(%rbx),%rdi
lea    0xe48(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1238 <main+0xc8>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbx),%rdx
lea    0xe30(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1190 <main+0x20>
mov    %r14d,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <get_volume@plt>
mov    %r14d,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <set_volume@plt>
mov    %r14d,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1090 <delta_volume@plt>
lea    0xddc(%rip),%rdi
call   1080 <perror@plt>
jmp    1190 <main+0x20>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"Usage: <dsp> <get|set|delta> <vol (0-100)>\0A\00"
@O_WRONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [4 x i8] c"get\00"
@.str.3 = [4 x i8] c"set\00"
@.str.4 = [6 x i8] c"delta\00"
@.str.5 = [48 x i8] c"Invalid command \22%s\22, needs \22get\22 or \22set\22 ...\0A\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 slt i32 %7, 3
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %59
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_WRONLY
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %59
22: ; preds = %12
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* %6
%30 = call i32 @get_volume(i32 %29)
store i32 %30, i32* %3
br label %59
31: ; preds = %22
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%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 %42
37: ; preds = %31
%38 = load i32, i32* %6
%39 = load i32, i32* %4
%40 = load i8**, i8*** %5
%41 = call i32 @set_volume(i32 %38, i32 %39, i8** %40)
store i32 %41, i32* %3
br label %59
42: ; preds = %31
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %42
%49 = load i32, i32* %6
%50 = load i32, i32* %4
%51 = load i8**, i8*** %5
%52 = call i32 @delta_volume(i32 %49, i32 %50, i8** %51)
store i32 %52, i32* %3
br label %59
53: ; preds = %42
%54 = load i32, i32* @stderr
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 2
%57 = load i8*, i8** %56
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i8* %57)
store i32 1, i32* %3
br label %59
59: ; preds = %53, %48, %37, %28, %20, %9
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"Usage: <dsp> <get|set|delta> <vol (0-100)>\0A\00"
@O_WRONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [4 x i8] c"get\00"
@.str.3 = [4 x i8] c"set\00"
@.str.4 = [6 x i8] c"delta\00"
@.str.5 = [48 x i8] c"Invalid command \22%s\22, needs \22get\22 or \22set\22 ...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %38
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_WRONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %38
15: ; preds = %7
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = tail call i32 @get_volume(i32 %11)
br label %38
22: ; preds = %15
%23 = load i8*, i8** %16
%24 = tail call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = tail call i32 @set_volume(i32 %11, i32 %0, i8** %1)
br label %38
28: ; preds = %22
%29 = load i8*, i8** %16
%30 = tail call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = tail call i32 @delta_volume(i32 %11, i32 %0, i8** %1)
br label %38
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %16
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %13, %20, %26, %32, %34, %4
%39 = phi i32 [ 1, %4 ], [ 1, %13 ], [ %21, %20 ], [ %27, %26 ], [ %33, %32 ], [ 1, %34 ]
ret i32 %39
}