swapin(name, addr) char *name;
{
  int fd;
  if ((fd = open(name, 0)) == -1)
    return -1;
  if ((read(fd, addr, 512)) < 0) {
    close(fd);
    return -1;
  }
  bdos(26, 0x80);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<swapin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1174 <swapin+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <swapin+0x87>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    $0x200,%edx
mov    $0x0,%al
call   1040 <read@plt>
cmp    $0x0,%eax
jge    11a5 <swapin+0x65>
mov    -0x18(%rbp),%edi
mov    $0x0,%al
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <swapin+0x87>
mov    $0x1a,%edi
mov    $0x80,%esi
mov    $0x0,%al
call   1050 <bdos@plt>
mov    -0x18(%rbp),%edi
mov    $0x0,%al
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swapin>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
xor    %esi,%esi
xor    %eax,%eax
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1180 <swapin+0x40>
mov    %eax,%ebp
xor    %r14d,%r14d
mov    %eax,%edi
mov    %ebx,%esi
mov    $0x200,%edx
xor    %eax,%eax
call   1040 <read@plt>
test   %eax,%eax
js     1188 <swapin+0x48>
mov    $0x1a,%edi
mov    $0x80,%esi
xor    %eax,%eax
call   1050 <bdos@plt>
jmp    118e <swapin+0x4e>
mov    $0xffffffff,%r14d
jmp    1197 <swapin+0x57>
mov    $0xffffffff,%r14d
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <close@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @swapin(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %7, i32 0)
store i32 %8, i32* %6
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %23
11: ; preds = %2
%12 = load i32, i32* %6
%13 = load i32, i32* %5
%14 = call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i32, i32, ...)*)(i32 %12, i32 %13, i32 512)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %6
%18 = call i32 (i32, ...) bitcast (i32 (...)* @close to i32 (i32, ...)*)(i32 %17)
store i32 -1, i32* %3
br label %23
19: ; preds = %11
%20 = call i32 (i32, i32, ...) bitcast (i32 (...)* @bdos to i32 (i32, i32, ...)*)(i32 26, i32 128)
%21 = load i32, i32* %6
%22 = call i32 (i32, ...) bitcast (i32 (...)* @close to i32 (i32, ...)*)(i32 %21)
store i32 0, i32* %3
br label %23
23: ; preds = %19, %16, %10
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @swapin(i8* %0, i32 %1) {
%3 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %0, i32 0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = tail call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i32, i32, ...)*)(i32 %3, i32 %1, i32 512)
%7 = icmp slt i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @bdos to i32 (i32, i32, ...)*)(i32 26, i32 128)
br label %10
10: ; preds = %5, %8
%11 = phi i32 [ 0, %8 ], [ -1, %5 ]
%12 = tail call i32 (i32, ...) bitcast (i32 (...)* @close to i32 (i32, ...)*)(i32 %3)
br label %13
13: ; preds = %10, %2
%14 = phi i32 [ -1, %2 ], [ %11, %10 ]
ret i32 %14
}