void tofile2(void) {
  unsigned short int i;
  unsigned short int j;
  unsigned short int n;
  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");
  i = open_(filename, 2);
  if (i == 1)
    puts0("open OK\r\n");
  else
    puts0("open not ok\r\n");
  puts0("count ? ");
  getsn(str, 256);
  n = atoi(str);
  puts0("n=");
  putdec(n);
  puts0("\r\n");
  for (i = 0; i < n; i++) {
    writec(0, '@');
    putch('@');
  }
  puts0("close rc=");
  putdec(close_(0));
  puts0("\r\n");
}


x86 assembly (clang, -O0):
<tofile2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1070 <puts0@plt>
movw   $0x0,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0x10,%eax
jge    11c9 <tofile2+0x49>
movzwl -0x2(%rbp),%eax
movb   $0x0,-0x120(%rbp,%rax,1)
mov    -0x2(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x2(%rbp)
jmp    119f <tofile2+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    1213 <tofile2+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    11e2 <tofile2+0x62>
movb   $0x0,-0x10(%rbp)
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1070 <puts0@plt>
lea    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1070 <puts0@plt>
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1070 <puts0@plt>
lea    -0x20(%rbp),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1060 <open_@plt>
mov    %ax,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0x1,%eax
jne    1272 <tofile2+0xf2>
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1070 <puts0@plt>
jmp    1280 <tofile2+0x100>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1070 <puts0@plt>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1070 <puts0@plt>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
mov    $0x0,%al
call   1030 <getsn@plt>
lea    -0x120(%rbp),%rdi
mov    $0x0,%al
call   1080 <atoi@plt>
mov    %ax,-0x6(%rbp)
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1070 <puts0@plt>
movzwl -0x6(%rbp),%edi
mov    $0x0,%al
call   1050 <putdec@plt>
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1070 <puts0@plt>
movw   $0x0,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
movzwl -0x6(%rbp),%ecx
cmp    %ecx,%eax
jge    131b <tofile2+0x19b>
xor    %edi,%edi
mov    $0x40,%esi
mov    $0x0,%al
call   1040 <writec@plt>
mov    $0x40,%edi
mov    $0x0,%al
call   1090 <putch@plt>
mov    -0x2(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x2(%rbp)
jmp    12e0 <tofile2+0x160>
lea    0xd12(%rip),%rdi
mov    $0x0,%al
call   1070 <puts0@plt>
xor    %edi,%edi
mov    $0x0,%al
call   10a0 <close_@plt>
mov    %eax,%edi
mov    $0x0,%al
call   1050 <putdec@plt>
lea    0xccb(%rip),%rdi
mov    $0x0,%al
call   1070 <puts0@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tofile2>:
push   %r14
push   %rbx
sub    $0x128,%rsp
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1070 <puts0@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   1030 <getsn@plt>
movaps 0x20(%rsp),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1070 <puts0@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <puts0@plt>
lea    0xe28(%rip),%rdi
xor    %eax,%eax
call   1070 <puts0@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1060 <open_@plt>
cmp    $0x1,%ax
lea    0xe0b(%rip),%rax
lea    0xe0e(%rip),%rdi
cmove  %rax,%rdi
xor    %eax,%eax
call   1070 <puts0@plt>
lea    0xe0a(%rip),%rdi
xor    %eax,%eax
call   1070 <puts0@plt>
mov    %r14,%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   1030 <getsn@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <atoi@plt>
mov    %eax,%ebx
lea    0xdea(%rip),%rdi
xor    %eax,%eax
call   1070 <puts0@plt>
mov    %ebx,%edi
and    $0xffff,%edi
xor    %eax,%eax
call   1050 <putdec@plt>
lea    0xda9(%rip),%rdi
xor    %eax,%eax
call   1070 <puts0@plt>
and    $0xffff,%ebx
je     129f <tofile2+0x11f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edi,%edi
mov    $0x40,%esi
xor    %eax,%eax
call   1040 <writec@plt>
mov    $0x40,%edi
xor    %eax,%eax
call   1090 <putch@plt>
add    $0xffffffff,%ebx
jne    1280 <tofile2+0x100>
lea    0xd8e(%rip),%rdi
xor    %eax,%eax
call   1070 <puts0@plt>
xor    %edi,%edi
xor    %eax,%eax
call   10a0 <close_@plt>
mov    %eax,%edi
xor    %eax,%eax
call   1050 <putdec@plt>
lea    0xd47(%rip),%rdi
xor    %eax,%eax
call   1070 <puts0@plt>
add    $0x128,%rsp
pop    %rbx
pop    %r14
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 = [10 x i8] c"open OK\0D\0A\00"
@.str.4 = [14 x i8] c"open not ok\0D\0A\00"
@.str.5 = [9 x i8] c"count ? \00"
@.str.6 = [3 x i8] c"n=\00"
@.str.7 = [3 x i8] c"\0D\0A\00"
@.str.8 = [10 x i8] c"close rc=\00"
define void @tofile2() {
%1 = alloca i16
%2 = alloca i16
%3 = alloca i16
%4 = alloca i16
%5 = alloca i8
%6 = alloca [18 x i8]
%7 = alloca [256 x i8]
%8 = 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 %9
9: ; preds = %17, %0
%10 = load i16, i16* %1
%11 = zext i16 %10 to i32
%12 = icmp slt i32 %11, 16
br i1 %12, label %13, label %20
13: ; preds = %9
%14 = load i16, i16* %1
%15 = zext i16 %14 to i64
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %15
store i8 0, i8* %16
br label %17
17: ; preds = %13
%18 = load i16, i16* %1
%19 = add i16 %18, 1
store i16 %19, i16* %1
br label %9
20: ; preds = %9
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%22 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @getsn to i32 (i8*, i32, ...)*)(i8* %21, i32 256)
store i16 0, i16* %1
br label %23
23: ; preds = %35, %20
%24 = load i16, i16* %1
%25 = zext i16 %24 to i32
%26 = icmp slt i32 %25, 16
br i1 %26, label %27, label %38
27: ; preds = %23
%28 = load i16, i16* %1
%29 = zext i16 %28 to i64
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = load i16, i16* %1
%33 = zext i16 %32 to i64
%34 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 %33
store i8 %31, i8* %34
br label %35
35: ; preds = %27
%36 = load i16, i16* %1
%37 = add i16 %36, 1
store i16 %37, i16* %1
br label %23
38: ; preds = %23
%39 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 16
store i8 0, i8* %39
%40 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%41 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 0
%42 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* %41)
%43 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%44 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 0
%45 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @open_ to i32 (i8*, i32, ...)*)(i8* %44, i32 2)
%46 = trunc i32 %45 to i16
store i16 %46, i16* %1
%47 = load i16, i16* %1
%48 = zext i16 %47 to i32
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %52
50: ; preds = %38
%51 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %54
52: ; preds = %38
%53 = 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 %54
54: ; preds = %52, %50
%55 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%57 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @getsn to i32 (i8*, i32, ...)*)(i8* %56, i32 256)
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%59 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %58)
%60 = trunc i32 %59 to i16
store i16 %60, i16* %3
%61 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%62 = load i16, i16* %3
%63 = zext i16 %62 to i32
%64 = call i32 (i32, ...) bitcast (i32 (...)* @putdec to i32 (i32, ...)*)(i32 %63)
%65 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i16 0, i16* %1
br label %66
66: ; preds = %75, %54
%67 = load i16, i16* %1
%68 = zext i16 %67 to i32
%69 = load i16, i16* %3
%70 = zext i16 %69 to i32
%71 = icmp slt i32 %68, %70
br i1 %71, label %72, label %78
72: ; preds = %66
%73 = call i32 (i32, i32, ...) bitcast (i32 (...)* @writec to i32 (i32, i32, ...)*)(i32 0, i32 64)
%74 = call i32 (i32, ...) bitcast (i32 (...)* @putch to i32 (i32, ...)*)(i32 64)
br label %75
75: ; preds = %72
%76 = load i16, i16* %1
%77 = add i16 %76, 1
store i16 %77, i16* %1
br label %66
78: ; preds = %66
%79 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
%80 = call i32 (i32, ...) bitcast (i32 (...)* @close_ to i32 (i32, ...)*)(i32 0)
%81 = call i32 (i32, ...) bitcast (i32 (...)* @putdec to i32 (i32, ...)*)(i32 %80)
%82 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 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 = [10 x i8] c"open OK\0D\0A\00"
@.str.4 = [14 x i8] c"open not ok\0D\0A\00"
@.str.5 = [9 x i8] c"count ? \00"
@.str.6 = [3 x i8] c"n=\00"
@.str.7 = [3 x i8] c"\0D\0A\00"
@.str.8 = [10 x i8] c"close rc=\00"
define void @tofile2() {
%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 = tail call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @getsn to i32 (i8*, i32, ...)*)(i8* %4, i32 256)
%7 = getelementptr inbounds [18 x i8], [18 x i8]* %1, i64 0, i64 16
store i8 0, i8* %7
%8 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* %2)
%10 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @open_ to i32 (i8*, i32, ...)*)(i8* %2, i32 2)
%12 = and i32 %11, 65535
%13 = icmp eq i32 %12, 1
%14 = select i1 %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0)
%15 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* %14)
%16 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%17 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @getsn to i32 (i8*, i32, ...)*)(i8* %4, i32 256)
%18 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %4)
%19 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%20 = and i32 %18, 65535
%21 = call i32 (i32, ...) bitcast (i32 (...)* @putdec to i32 (i32, ...)*)(i32 %20)
%22 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%23 = icmp eq i32 %20, 0
br i1 %23, label %30, label %24
24: ; preds = %0, %24
%25 = phi i32 [ %28, %24 ], [ 0, %0 ]
%26 = call i32 (i32, i32, ...) bitcast (i32 (...)* @writec to i32 (i32, i32, ...)*)(i32 0, i32 64)
%27 = call i32 (i32, ...) bitcast (i32 (...)* @putch to i32 (i32, ...)*)(i32 64)
%28 = add nuw nsw i32 %25, 1
%29 = icmp eq i32 %28, %20
br i1 %29, label %30, label %24
30: ; preds = %24, %0
%31 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
%32 = call i32 (i32, ...) bitcast (i32 (...)* @close_ to i32 (i32, ...)*)(i32 0)
%33 = call i32 (i32, ...) bitcast (i32 (...)* @putdec to i32 (i32, ...)*)(i32 %32)
%34 = call i32 (i8*, ...) bitcast (i32 (...)* @puts0 to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
ret void
}