#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(unsigned char *, unsigned char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putc(unsigned short, int /*<<< orphan*/ *);
int /*<<< orphan*/ scanf(char *, unsigned short *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  unsigned char *filename, *filemode;
  unsigned short byte;
  FILE *outfile;
  char a_out = 0;
  unsigned char argt;
  char *cmd = argv[0];
  while (--argc > 0 && (*++argv)[0] == '-')
    while (argt = *++argv[0])
      switch (argt) {
      case 'a':
        a_out = 1;
        break;
      default:
        usage(cmd);
        break;
      }
  if (argc != 1) {
    usage(cmd);
  }
  filename = *argv;
  (a_out) ? (filemode = "ab") : (filemode = "wb");
  outfile = fopen(filename, filemode);
  if (outfile == NULL) {
    printf("Unable to open file %s\n", filename);
    exit(-1);
  }
  printf("Byte to write: ");
  scanf("%hu", &byte);
  putc(byte, outfile);
  fclose(outfile);
  exit(1);
}


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)
movb   $0x0,-0x31(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x41(%rbp)
jle    11cb <main+0x5b>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    11db <main+0x6b>
jmp    122b <main+0xbb>
jmp    11e0 <main+0x70>
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,(%rcx)
mov    0x1(%rax),%al
mov    %al,-0x32(%rbp)
cmp    $0x0,%al
je     1226 <main+0xb6>
mov    -0x32(%rbp),%al
sub    $0x61,%al
jne    1218 <main+0xa8>
jmp    120f <main+0x9f>
movb   $0x1,-0x31(%rbp)
jmp    1221 <main+0xb1>
mov    -0x40(%rbp),%rdi
call   1060 <usage@plt>
jmp    11e0 <main+0x70>
jmp    1195 <main+0x25>
cmpl   $0x1,-0x8(%rbp)
je     123e <main+0xce>
mov    -0x40(%rbp),%rdi
call   1060 <usage@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movsbl -0x31(%rbp),%eax
cmp    $0x0,%eax
je     1266 <main+0xf6>
lea    0xda3(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1271 <main+0x101>
lea    0xd96(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12a9 <main+0x139>
mov    -0x18(%rbp),%rsi
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd70(%rip),%rdi
lea    -0x22(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x22(%rbp),%ax
mov    -0x30(%rbp),%rsi
movzwl %ax,%edi
call   1050 <putc@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    (%rsi),%r14
cmp    $0x2,%edi
jl     11e5 <main+0x75>
mov    %edi,%r15d
xor    %r13d,%r13d
jmp    1199 <main+0x29>
xchg   %ax,%ax
cmp    $0x3,%r15d
mov    %ebp,%r15d
jl     11ef <main+0x7f>
lea    -0x1(%r15),%ebp
mov    0x8(%r12),%rbx
add    $0x8,%r12
cmpb   $0x2d,(%rbx)
jne    11ea <main+0x7a>
mov    %rbx,%rax
xchg   %ax,%ax
lea    0x1(%rax),%rbx
mov    %rbx,(%r12)
movzbl 0x1(%rax),%eax
test   %al,%al
je     1190 <main+0x20>
cmp    $0x61,%al
je     11e0 <main+0x70>
mov    %r14,%rdi
call   1060 <usage@plt>
mov    (%r12),%rax
jmp    11b0 <main+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x1,%r13b
jmp    11ab <main+0x3b>
xor    %r13d,%r13d
jmp    11ef <main+0x7f>
cmp    $0x1,%ebp
je     11fb <main+0x8b>
mov    %r14,%rdi
call   1060 <usage@plt>
mov    (%r12),%rbx
test   %r13b,%r13b
lea    0xdfe(%rip),%rax
lea    0xdf4(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
jne    1238 <main+0xc8>
lea    0xde2(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    %rax,%r14
lea    0xddc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdde(%rip),%rdi
lea    0x6(%rsp),%rsi
call   1070 <scanf@plt>
movzwl 0x6(%rsp),%edi
mov    %r14,%rsi
call   1050 <putc@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"ab\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [24 x i8] c"Unable to open file %s\0A\00"
@.str.3 = [16 x i8] c"Byte to write: \00"
@.str.4 = [4 x i8] c"%hu\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i16
%9 = alloca i32*
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 0, i8* %10
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
store i8* %15, i8** %12
br label %16
16: ; preds = %46, %2
%17 = load i32, i32* %4
%18 = add nsw i32 %17, -1
store i32 %18, i32* %4
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i32 1
store i8** %22, i8*** %5
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 45
br label %28
28: ; preds = %20, %16
%29 = phi i1 [ false, %16 ], [ %27, %20 ]
br i1 %29, label %30, label %47
30: ; preds = %28
br label %31
31: ; preds = %45, %30
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %33
%36 = load i8, i8* %35
store i8 %36, i8* %11
%37 = icmp ne i8 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %31
%39 = load i8, i8* %11
%40 = zext i8 %39 to i32
switch i32 %40, label %42 [
i32 97, label %41
]
41: ; preds = %38
store i8 1, i8* %10
br label %45
42: ; preds = %38
%43 = load i8*, i8** %12
%44 = call i32 @usage(i8* %43)
br label %45
45: ; preds = %42, %41
br label %31
46: ; preds = %31
br label %16
47: ; preds = %28
%48 = load i32, i32* %4
%49 = icmp ne i32 %48, 1
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i8*, i8** %12
%52 = call i32 @usage(i8* %51)
br label %53
53: ; preds = %50, %47
%54 = load i8**, i8*** %5
%55 = load i8*, i8** %54
store i8* %55, i8** %6
%56 = load i8, i8* %10
%57 = sext i8 %56 to i32
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %53
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %7
br label %61
60: ; preds = %53
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %61
61: ; preds = %60, %59
%62 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %59 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %60 ]
%63 = load i8*, i8** %6
%64 = load i8*, i8** %7
%65 = call i32* @fopen(i8* %63, i8* %64)
store i32* %65, i32** %9
%66 = load i32*, i32** %9
%67 = icmp eq i32* %66, null
br i1 %67, label %68, label %72
68: ; preds = %61
%69 = load i8*, i8** %6
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %69)
%71 = call i32 @exit(i32 -1)
unreachable
72: ; preds = %61
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%74 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i16* %8)
%75 = load i16, i16* %8
%76 = load i32*, i32** %9
%77 = call i32 @putc(i16 zeroext %75, i32* %76)
%78 = load i32*, i32** %9
%79 = call i32 @fclose(i32* %78)
%80 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"ab\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [24 x i8] c"Unable to open file %s\0A\00"
@.str.3 = [16 x i8] c"Byte to write: \00"
@.str.4 = [4 x i8] c"%hu\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = bitcast i16* %3 to i8*
%5 = load i8*, i8** %1
%6 = icmp sgt i32 %0, 1
br i1 %6, label %9, label %32
7: ; preds = %23
%8 = icmp sgt i32 %10, 2
br i1 %8, label %9, label %32
9: ; preds = %2, %7
%10 = phi i32 [ %13, %7 ], [ %0, %2 ]
%11 = phi i8** [ %14, %7 ], [ %1, %2 ]
%12 = phi i8 [ %22, %7 ], [ 0, %2 ]
%13 = add nsw i32 %10, -1
%14 = getelementptr inbounds i8*, i8** %11, i64 1
%15 = load i8*, i8** %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 45
br i1 %17, label %20, label %30
18: ; preds = %23
%19 = getelementptr inbounds i8, i8* %24, i64 1
br label %20
20: ; preds = %9, %18
%21 = phi i8* [ %19, %18 ], [ %15, %9 ]
%22 = phi i8 [ 1, %18 ], [ %12, %9 ]
br label %23
23: ; preds = %20, %27
%24 = phi i8* [ %29, %27 ], [ %21, %20 ]
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8* %25, i8** %14
%26 = load i8, i8* %25
switch i8 %26, label %27 [
i8 0, label %7
i8 97, label %18
]
27: ; preds = %23
%28 = tail call i32 @usage(i8* %5)
%29 = load i8*, i8** %14
br label %23
30: ; preds = %9
%31 = icmp eq i32 %13, 1
br i1 %31, label %37, label %32
32: ; preds = %7, %2, %30
%33 = phi i8 [ %12, %30 ], [ 0, %2 ], [ %22, %7 ]
%34 = phi i8** [ %14, %30 ], [ %1, %2 ], [ %14, %7 ]
%35 = tail call i32 @usage(i8* %5)
%36 = load i8*, i8** %34
br label %37
37: ; preds = %32, %30
%38 = phi i8* [ %36, %32 ], [ %15, %30 ]
%39 = phi i8 [ %33, %32 ], [ %12, %30 ]
%40 = icmp eq i8 %39, 0
%41 = select i1 %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0)
%42 = tail call i32* @fopen(i8* %38, i8* %41)
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %47
44: ; preds = %37
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%46 = tail call i32 @exit(i32 -1)
unreachable
47: ; preds = %37
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i16* %3)
%50 = load i16, i16* %3
%51 = call i32 @putc(i16 zeroext %50, i32* %42)
%52 = call i32 @fclose(i32* %42)
%53 = call i32 @exit(i32 1)
unreachable
}