void tofile(void) {
  unsigned short int i;
  unsigned short int j;
  unsigned short int equal;
  unsigned char device;
  unsigned char filename[16 + 2];
  unsigned char str[256];
  puts0("file ? ");
  for (i = 0; i < 16; i++)
    str[i] = 0;
  getsn(str, 256);
  for (i = 0; i < 16; i++)
    filename[i] = str[i];
  filename[16] = 0;
  puts0("\r\n'");
  puts0(filename);
  puts0("'\r\n");
  puts0("data to file ? ");
  for (i = 0; i < 256; i++)
    str[i] = 0;
  getsn(str, 256);
  puts0("\r\n'");
  puts0(str);
  puts0("'\r\n");
  i = open_(filename, 2);
  if (i == 1) {
  } else
    puts0("open not ok\r\n");
  for (i = 0; i < 256; i++)
    if (str[i]) {
      writec(0, str[i]);
      putch(str[i]);
    }
  close_(0);
}


x86 assembly (clang, -O0):
<tofile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1060 <puts0@plt>
movw   $0x0,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0x10,%eax
jge    11a9 <tofile+0x49>
movzwl -0x2(%rbp),%eax
movb   $0x0,-0x120(%rbp,%rax,1)
mov    -0x2(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x2(%rbp)
jmp    117f <tofile+0x1f>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
mov    $0x0,%al
call   1030 <getsn@plt>
movw   $0x0,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0x10,%eax
jge    11f3 <tofile+0x93>
movzwl -0x2(%rbp),%eax
mov    -0x120(%rbp,%rax,1),%cl
movzwl -0x2(%rbp),%eax
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0x2(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x2(%rbp)
jmp    11c2 <tofile+0x62>
movb   $0x0,-0x10(%rbp)
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1060 <puts0@plt>
lea    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1060 <puts0@plt>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1060 <puts0@plt>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1060 <puts0@plt>
movw   $0x0,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0x100,%eax
jge    125e <tofile+0xfe>
movzwl -0x2(%rbp),%eax
movb   $0x0,-0x120(%rbp,%rax,1)
mov    -0x2(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x2(%rbp)
jmp    1232 <tofile+0xd2>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
mov    $0x0,%al
call   1030 <getsn@plt>
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1060 <puts0@plt>
lea    -0x120(%rbp),%rdi
mov    $0x0,%al
call   1060 <puts0@plt>
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1060 <puts0@plt>
lea    -0x20(%rbp),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1050 <open_@plt>
mov    %ax,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0x1,%eax
jne    12c1 <tofile+0x161>
jmp    12cf <tofile+0x16f>
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1060 <puts0@plt>
movw   $0x0,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0x100,%eax
jge    1334 <tofile+0x1d4>
movzwl -0x2(%rbp),%eax
cmpb   $0x0,-0x120(%rbp,%rax,1)
je     131e <tofile+0x1be>
movzwl -0x2(%rbp),%eax
movzbl -0x120(%rbp,%rax,1),%esi
ff
xor    %edi,%edi
mov    $0x0,%al
call   1040 <writec@plt>
movzwl -0x2(%rbp),%eax
movzbl -0x120(%rbp,%rax,1),%edi
ff
mov    $0x0,%al
call   1070 <putch@plt>
jmp    1323 <tofile+0x1c3>
mov    -0x2(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x2(%rbp)
jmp    12d5 <tofile+0x175>
xor    %edi,%edi
mov    $0x0,%al
call   1080 <close_@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tofile>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x128,%rsp
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1060 <puts0@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   1030 <getsn@plt>
movaps 0x20(%rsp),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
lea    0xe53(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <puts0@plt>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <puts0@plt>
lea    0xe39(%rip),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <puts0@plt>
lea    0xe2c(%rip),%rdi
xor    %eax,%eax
call   1060 <puts0@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0x110(%rsp)
mov    %rbx,%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   1030 <getsn@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <puts0@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <puts0@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <puts0@plt>
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <open_@plt>
cmp    $0x1,%ax
je     12a4 <tofile+0x144>
lea    0xd7b(%rip),%rdi
xor    %eax,%eax
call   1060 <puts0@plt>
xor    %ebx,%ebx
jmp    12bd <tofile+0x15d>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    $0x100,%rbx
je     12dd <tofile+0x17d>
movzbl 0x20(%rsp,%rbx,1),%esi
test   %esi,%esi
je     12b0 <tofile+0x150>
xor    %edi,%edi
xor    %eax,%eax
call   1040 <writec@plt>
movzbl 0x20(%rsp,%rbx,1),%edi
xor    %eax,%eax
call   1070 <putch@plt>
jmp    12b0 <tofile+0x150>
xor    %edi,%edi
xor    %eax,%eax
call   1080 <close_@plt>
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"file ? \00"
@.str.1 = [4 x i8] c"\0D\0A'\00"
@.str.2 = [4 x i8] c"'\0D\0A\00"
@.str.3 = [16 x i8] c"data to file ? \00"
@.str.4 = [14 x i8] c"open not ok\0D\0A\00"
define void @tofile() {
%1 = alloca i16
%2 = alloca i16
%3 = alloca i16
%4 = alloca i8
%5 = alloca [18 x i8]
%6 = alloca [256 x i8]
%7 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i16 0, i16* %1
br label %8
8: ; preds = %16, %0
%9 = load i16, i16* %1
%10 = zext i16 %9 to i32
%11 = icmp slt i32 %10, 16
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = load i16, i16* %1
%14 = zext i16 %13 to i64
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %12
%17 = load i16, i16* %1
%18 = add i16 %17, 1
store i16 %18, i16* %1
br label %8
19: ; preds = %8
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%21 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @getsn to i32 (i8*, i32, ...)*)(i8* %20, i32 256)
store i16 0, i16* %1
br label %22
22: ; preds = %34, %19
%23 = load i16, i16* %1
%24 = zext i16 %23 to i32
%25 = icmp slt i32 %24, 16
br i1 %25, label %26, label %37
26: ; preds = %22
%27 = load i16, i16* %1
%28 = zext i16 %27 to i64
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = load i16, i16* %1
%32 = zext i16 %31 to i64
%33 = getelementptr inbounds [18 x i8], [18 x i8]* %5, i64 0, i64 %32
store i8 %30, i8* %33
br label %34
34: ; preds = %26
%35 = load i16, i16* %1
%36 = add i16 %35, 1
store i16 %36, i16* %1
br label %22
37: ; preds = %22
%38 = getelementptr inbounds [18 x i8], [18 x i8]* %5, i64 0, i64 16
store i8 0, i8* %38
%39 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%40 = getelementptr inbounds [18 x i8], [18 x i8]* %5, i64 0, i64 0
%41 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* %40)
%42 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i16 0, i16* %1
br label %44
44: ; preds = %52, %37
%45 = load i16, i16* %1
%46 = zext i16 %45 to i32
%47 = icmp slt i32 %46, 256
br i1 %47, label %48, label %55
48: ; preds = %44
%49 = load i16, i16* %1
%50 = zext i16 %49 to i64
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %50
store i8 0, i8* %51
br label %52
52: ; preds = %48
%53 = load i16, i16* %1
%54 = add i16 %53, 1
store i16 %54, i16* %1
br label %44
55: ; preds = %44
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%57 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @getsn to i32 (i8*, i32, ...)*)(i8* %56, i32 256)
%58 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%60 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* %59)
%61 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%62 = getelementptr inbounds [18 x i8], [18 x i8]* %5, i64 0, i64 0
%63 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @open_ to i32 (i8*, i32, ...)*)(i8* %62, i32 2)
%64 = trunc i32 %63 to i16
store i16 %64, i16* %1
%65 = load i16, i16* %1
%66 = zext i16 %65 to i32
%67 = icmp eq i32 %66, 1
br i1 %67, label %68, label %69
68: ; preds = %55
br label %71
69: ; preds = %55
%70 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %71
71: ; preds = %69, %68
store i16 0, i16* %1
br label %72
72: ; preds = %96, %71
%73 = load i16, i16* %1
%74 = zext i16 %73 to i32
%75 = icmp slt i32 %74, 256
br i1 %75, label %76, label %99
76: ; preds = %72
%77 = load i16, i16* %1
%78 = zext i16 %77 to i64
%79 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %78
%80 = load i8, i8* %79
%81 = icmp ne i8 %80, 0
br i1 %81, label %82, label %95
82: ; preds = %76
%83 = load i16, i16* %1
%84 = zext i16 %83 to i64
%85 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %84
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
%88 = call i32 (i32, i32, ...) bitcast (i32 (...)* @writec to i32 (i32, i32, ...)*)(i32 0, i32 %87)
%89 = load i16, i16* %1
%90 = zext i16 %89 to i64
%91 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %90
%92 = load i8, i8* %91
%93 = zext i8 %92 to i32
%94 = call i32 (i32, ...) bitcast (i32 (...)* @putch to i32 (i32, ...)*)(i32 %93)
br label %95
95: ; preds = %82, %76
br label %96
96: ; preds = %95
%97 = load i16, i16* %1
%98 = add i16 %97, 1
store i16 %98, i16* %1
br label %72
99: ; preds = %72
%100 = call i32 (i32, ...) bitcast (i32 (...)* @close_ to i32 (i32, ...)*)(i32 0)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"file ? \00"
@.str.1 = [4 x i8] c"\0D\0A'\00"
@.str.2 = [4 x i8] c"'\0D\0A\00"
@.str.3 = [16 x i8] c"data to file ? \00"
@.str.4 = [14 x i8] c"open not ok\0D\0A\00"
define void @tofile() {
%1 = alloca [18 x i8]
%2 = getelementptr inbounds [18 x i8], [18 x i8]* %1, i64 0, i64 0
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [18 x i8], [18 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = tail call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @getsn to i32 (i8*, i32, ...)*)(i8* %6, i32 256)
%9 = getelementptr inbounds [18 x i8], [18 x i8]* %1, i64 0, i64 16
store i8 0, i8* %9
%10 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* %5)
%12 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @getsn to i32 (i8*, i32, ...)*)(i8* %6, i32 256)
%15 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* %6)
%17 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @open_ to i32 (i8*, i32, ...)*)(i8* %5, i32 2)
%19 = and i32 %18, 65535
%20 = icmp eq i32 %19, 1
br i1 %20, label %23, label %21
21: ; preds = %0
%22 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %23
23: ; preds = %0, %21
br label %24
24: ; preds = %23, %35
%25 = phi i64 [ %36, %35 ], [ 0, %23 ]
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %35, label %29
29: ; preds = %24
%30 = zext i8 %27 to i32
%31 = call i32 (i32, i32, ...) bitcast (i32 (...)* @writec to i32 (i32, i32, ...)*)(i32 0, i32 %30)
%32 = load i8, i8* %26
%33 = zext i8 %32 to i32
%34 = call i32 (i32, ...) bitcast (i32 (...)* @putch to i32 (i32, ...)*)(i32 %33)
br label %35
35: ; preds = %24, %29
%36 = add nuw nsw i64 %25, 1
%37 = icmp eq i64 %36, 256
br i1 %37, label %38, label %24
38: ; preds = %35
%39 = call i32 (i32, ...) bitcast (i32 (...)* @close_ to i32 (i32, ...)*)(i32 0)
ret void
}