#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*/ temp;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
unsigned short CHAR_BIT;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
scalar_t__ scanf(char *, unsigned short *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  if (argc != 2) {
    return 1;
  }
  int out = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0600);
  unsigned short temp;
  char buf[sizeof(temp)];
  while (scanf("%hu", &temp) > 0) {
    buf[1] = temp;
    buf[0] = temp >> CHAR_BIT;
    write(out, buf, sizeof(buf));
  }
  close(out);
  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     116c <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    11f5 <main+0xb5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
mov    0x2e74(%rip),%rax
or     (%rax),%esi
mov    0x2e63(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
lea    0xe5d(%rip),%rdi
lea    -0x16(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x0,%rax
jle    11e6 <main+0xa6>
mov    -0x16(%rbp),%ax
mov    %al,-0x17(%rbp)
movzwl -0x16(%rbp),%eax
mov    0x2e08(%rip),%rcx
movzwl (%rcx),%ecx
sar    %cl,%eax
mov    %al,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
jmp    119c <main+0x5c>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x1,%eax
cmp    $0x2,%edi
jne    1209 <main+0xc9>
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e5e(%rip),%rcx
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x8(%rsi),%rdi
mov    0x2e78(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
mov    $0x180,%edx
call   1060 <open@plt>
mov    %eax,%ebx
lea    0xe71(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
test   %rax,%rax
jle    11f3 <main+0xb3>
mov    0x2e2b(%rip),%r13
lea    0xe(%rsp),%r14
lea    0xe4f(%rip),%r15
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
movzwl 0xc(%rsp),%eax
mov    %al,0xf(%rsp)
movzbl 0x0(%r13),%ecx
shr    %cl,%eax
mov    %al,0xe(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
test   %rax,%rax
jg     11c0 <main+0x80>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str = [4 x i8] c"%hu\00"
@CHAR_BIT = global i16 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i16
%8 = alloca [2 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 1, i32* %3
br label %42
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 = load i32, i32* @O_CREAT
%18 = or i32 %16, %17
%19 = load i32, i32* @O_TRUNC
%20 = or i32 %18, %19
%21 = call i32 @open(i8* %15, i32 %20, i32 384)
store i32 %21, i32* %6
br label %22
22: ; preds = %25, %12
%23 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16* %7)
%24 = icmp sgt i64 %23, 0
br i1 %24, label %25, label %39
25: ; preds = %22
%26 = load i16, i16* %7
%27 = trunc i16 %26 to i8
%28 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 1
store i8 %27, i8* %28
%29 = load i16, i16* %7
%30 = zext i16 %29 to i32
%31 = load i16, i16* @CHAR_BIT
%32 = zext i16 %31 to i32
%33 = ashr i32 %30, %32
%34 = trunc i32 %33 to i8
%35 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
store i8 %34, i8* %35
%36 = load i32, i32* %6
%37 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%38 = call i32 @write(i32 %36, i8* %37, i32 2)
br label %22
39: ; preds = %22
%40 = load i32, i32* %6
%41 = call i32 @close(i32 %40)
store i32 0, i32* %3
br label %42
42: ; preds = %39, %11
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str = [4 x i8] c"%hu\00"
@CHAR_BIT = global i16 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = alloca [2 x i8]
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %34
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_WRONLY
%10 = load i32, i32* @O_CREAT
%11 = or i32 %10, %9
%12 = load i32, i32* @O_TRUNC
%13 = or i32 %11, %12
%14 = tail call i32 @open(i8* %8, i32 %13, i32 384)
%15 = bitcast i16* %3 to i8*
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%17 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16* %3)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %6
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
br label %21
21: ; preds = %19, %21
%22 = load i16, i16* %3
%23 = trunc i16 %22 to i8
store i8 %23, i8* %20
%24 = zext i16 %22 to i32
%25 = load i16, i16* @CHAR_BIT
%26 = zext i16 %25 to i32
%27 = lshr i32 %24, %26
%28 = trunc i32 %27 to i8
store i8 %28, i8* %16
%29 = call i32 @write(i32 %14, i8* %16, i32 2)
%30 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16* %3)
%31 = icmp sgt i64 %30, 0
br i1 %31, label %21, label %32
32: ; preds = %21, %6
%33 = call i32 @close(i32 %14)
br label %34
34: ; preds = %2, %32
%35 = phi i32 [ 0, %32 ], [ 1, %2 ]
ret i32 %35
}