#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt(int, char **, char *);
int optind;
int /*<<< orphan*/ print_usage(char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ tee(char *, int);
int main(int argc, char **argv) {
  int opt;
  int append = 0;
  while ((opt = getopt(argc, argv, "a")) != -1) {
    switch (opt) {
    case 'a':
      append = 1;
      break;
    default:
      print_usage(argv[0]);
      return 1;
    }
  }
  if (optind != argc - 1) {
    print_usage(argv[0]);
    return 1;
  }
  if (tee(argv[optind], append) != 0) {
    fprintf(stderr, "Error while performing tee: %s", strerror(errno));
    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)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe85(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11c6 <main+0x76>
mov    -0x14(%rbp),%eax
sub    $0x61,%eax
jne    11a9 <main+0x59>
jmp    119d <main+0x4d>
movl   $0x1,-0x18(%rbp)
jmp    11c1 <main+0x71>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <print_usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1258 <main+0x108>
jmp    116d <main+0x1d>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     11f5 <main+0xa5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <print_usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1258 <main+0x108>
mov    -0x10(%rbp),%rax
mov    0x2de8(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%esi
call   1040 <tee@plt>
cmp    $0x0,%rax
je     1251 <main+0x101>
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xdc2(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1258 <main+0x108>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
xor    %ecx,%ecx
lea    0xe9b(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ecx,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <getopt@plt>
mov    $0x1,%ecx
cmp    $0x61,%eax
je     1170 <main+0x20>
cmp    $0xffffffff,%eax
jne    11d9 <main+0x89>
mov    0x2e53(%rip),%rax
movslq (%rax),%rax
add    $0xffffffff,%ebx
cmp    %ebx,%eax
jne    11d9 <main+0x89>
mov    (%r14,%rax,8),%rdi
mov    %ebp,%esi
call   1040 <tee@plt>
test   %rax,%rax
je     11f1 <main+0xa1>
mov    0x2e22(%rip),%rax
mov    (%rax),%ebx
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe35(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
jmp    11e1 <main+0x91>
mov    (%r14),%rdi
call   1060 <print_usage@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    11e6 <main+0x96>

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@optind = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"Error while performing tee: %s\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %8
8: ; preds = %21, %2
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @getopt(i32 %9, i8** %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %6
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %22
13: ; preds = %8
%14 = load i32, i32* %6
switch i32 %14, label %16 [
i32 97, label %15
]
15: ; preds = %13
store i32 1, i32* %7
br label %21
16: ; preds = %13
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @print_usage(i8* %19)
store i32 1, i32* %3
br label %47
21: ; preds = %15
br label %8
22: ; preds = %8
%23 = load i32, i32* @optind
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 1
%26 = icmp ne i32 %23, %25
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @print_usage(i8* %30)
store i32 1, i32* %3
br label %47
32: ; preds = %22
%33 = load i8**, i8*** %5
%34 = load i32, i32* @optind
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = load i32, i32* %7
%39 = call i64 @tee(i8* %37, i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %32
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %44)
store i32 1, i32* %3
br label %47
46: ; preds = %32
store i32 0, i32* %3
br label %47
47: ; preds = %46, %41, %27, %16
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@optind = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"Error while performing tee: %s\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i32 [ 0, %2 ], [ 1, %3 ]
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
switch i32 %5, label %6 [
i32 -1, label %9
i32 97, label %3
]
6: ; preds = %3
%7 = load i8*, i8** %1
%8 = tail call i32 @print_usage(i8* %7)
br label %27
9: ; preds = %3
%10 = load i32, i32* @optind
%11 = add nsw i32 %0, -1
%12 = icmp eq i32 %10, %11
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = load i8*, i8** %1
%15 = tail call i32 @print_usage(i8* %14)
br label %27
16: ; preds = %9
%17 = sext i32 %10 to i64
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = tail call i64 @tee(i8* %19, i32 %4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = tail call i8* @strerror(i32 %24)
%26 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %16, %22, %13, %6
%28 = phi i32 [ 1, %6 ], [ 1, %13 ], [ 1, %22 ], [ 0, %16 ]
ret i32 %28
}