#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 O_CREAT;
int O_EXCL;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int modulate(int, int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int infd = -1, outfd = -1;
  int retval;
  if (argc < 3) {
    usage();
    return 0;
  }
  if (strcmp(argv[1], "-") == 0) {
    infd = 0;
  } else {
    infd = open(argv[1], O_RDONLY);
  }
  if (infd < 0) {
    perror("Error opening input file");
    return -1;
  }
  if (strcmp(argv[2], "-") == 0) {
    outfd = 1;
  } else {
    outfd = open(argv[2], O_WRONLY | O_CREAT | O_EXCL, 0777);
  }
  if (outfd < 0) {
    perror("Error opening output file");
    return -1;
  }
  while ((retval = modulate(infd, outfd)))
    ;
  close(outfd);
  close(infd);
  return retval;
}


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)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11a1 <main+0x41>
mov    $0x0,%al
call   1060 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    12bd <main+0x15d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe50(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11cb <main+0x6b>
movl   $0x0,-0x14(%rbp)
jmp    11e6 <main+0x86>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1208 <main+0xa8>
lea    0xe0b(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12bd <main+0x15d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xde9(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1232 <main+0xd2>
movl   $0x1,-0x18(%rbp)
jmp    1264 <main+0x104>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d7f(%rip),%rax
mov    (%rax),%esi
mov    0x2dae(%rip),%rax
or     (%rax),%esi
mov    0x2d7d(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1286 <main+0x126>
lea    0xda6(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12bd <main+0x15d>
jmp    128b <main+0x12b>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <modulate@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     12a7 <main+0x147>
jmp    128b <main+0x12b>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-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     1177 <main+0x17>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <usage@plt>
jmp    123d <main+0xdd>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe7b(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11b2 <main+0x52>
mov    0x8(%r14),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11b4 <main+0x54>
lea    0xe52(%rip),%rdi
jmp    1201 <main+0xa1>
xor    %ebx,%ebx
mov    0x10(%r14),%rdi
lea    0xe41(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     120d <main+0xad>
mov    0x2df0(%rip),%rax
mov    0x2e21(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%r14),%rdi
mov    0x2dea(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
xor    %eax,%eax
call   1070 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1220 <main+0xc0>
lea    0xe1a(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%ebx
jmp    123d <main+0xdd>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <modulate@plt>
test   %eax,%eax
jne    1220 <main+0xc0>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@O_RDONLY = global i32 0
@.str.1 = [25 x i8] c"Error opening input file\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.2 = [26 x i8] c"Error opening output file\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 -1, i32* %7
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (...) @usage()
store i32 0, i32* %3
br label %66
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 0, i32* %6
br label %26
20: ; preds = %13
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_RDONLY
%25 = call i32 (i8*, i32, ...) @open(i8* %23, i32 %24)
store i32 %25, i32* %6
br label %26
26: ; preds = %20, %19
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %66
31: ; preds = %26
%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 ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %31
store i32 1, i32* %7
br label %48
38: ; preds = %31
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = load i32, i32* @O_WRONLY
%43 = load i32, i32* @O_CREAT
%44 = or i32 %42, %43
%45 = load i32, i32* @O_EXCL
%46 = or i32 %44, %45
%47 = call i32 (i8*, i32, ...) @open(i8* %41, i32 %46, i32 511)
store i32 %47, i32* %7
br label %48
48: ; preds = %38, %37
%49 = load i32, i32* %7
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %66
53: ; preds = %48
br label %54
54: ; preds = %59, %53
%55 = load i32, i32* %6
%56 = load i32, i32* %7
%57 = call i32 @modulate(i32 %55, i32 %56)
store i32 %57, i32* %8
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %54
br label %54
60: ; preds = %54
%61 = load i32, i32* %7
%62 = call i32 @close(i32 %61)
%63 = load i32, i32* %6
%64 = call i32 @close(i32 %63)
%65 = load i32, i32* %8
store i32 %65, i32* %3
br label %66
66: ; preds = %60, %51, %29, %11
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@O_RDONLY = global i32 0
@.str.1 = [25 x i8] c"Error opening input file\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.2 = [26 x i8] c"Error opening output file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %43
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %6
%12 = load i8*, i8** %7
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 (i8*, i32, ...) @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %43
18: ; preds = %6, %11
%19 = phi i32 [ %14, %11 ], [ 0, %6 ]
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %18
%25 = load i8*, i8** %20
%26 = load i32, i32* @O_WRONLY
%27 = load i32, i32* @O_CREAT
%28 = or i32 %27, %26
%29 = load i32, i32* @O_EXCL
%30 = or i32 %28, %29
%31 = tail call i32 (i8*, i32, ...) @open(i8* %25, i32 %30, i32 511)
%32 = icmp slt i32 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %18, %24
%34 = phi i32 [ %31, %24 ], [ 1, %18 ]
br label %37
35: ; preds = %24
%36 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %43
37: ; preds = %33, %37
%38 = tail call i32 @modulate(i32 %19, i32 %34)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %37
40: ; preds = %37
%41 = tail call i32 @close(i32 %34)
%42 = tail call i32 @close(i32 %19)
br label %43
43: ; preds = %40, %35, %16, %4
%44 = phi i32 [ 0, %4 ], [ -1, %16 ], [ -1, %35 ], [ 0, %40 ]
ret i32 %44
}