copen(filename, type) char *filename;
int type;
{
  int fn;
  switch (type) {
  case 'r':
    type = 0;
  case 0:
    fn = open(filename, 0);
    break;
  case 'a':
    type = 2;
  case 2:
    if ((fn = open(filename, 1)) >= 0)
      break;
  case 'w':
    type = 1;
  case 1:
    fn = creat(filename, 0666);
    break;
  default:
    IEH3err("copen: bad file %s", filename);
  }
  if (fn >= 0)
    IEH3mbuf(fn, type);
  return (fn);
}


x86 assembly (clang, -O0):
<copen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     11be <copen+0x7e>
jmp    1162 <copen+0x22>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     1207 <copen+0xc7>
jmp    1173 <copen+0x33>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     11da <copen+0x9a>
jmp    1184 <copen+0x44>
mov    -0x14(%rbp),%eax
sub    $0x61,%eax
je     11d3 <copen+0x93>
jmp    1195 <copen+0x55>
mov    -0x14(%rbp),%eax
sub    $0x72,%eax
je     11b7 <copen+0x77>
jmp    11a6 <copen+0x66>
mov    -0x14(%rbp),%eax
sub    $0x77,%eax
je     1200 <copen+0xc0>
jmp    121f <copen+0xdf>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
jmp    1231 <copen+0xf1>
movl   $0x2,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jl     11fb <copen+0xbb>
jmp    1231 <copen+0xf1>
jmp    1200 <copen+0xc0>
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1b6,%esi
mov    $0x0,%al
call   1060 <creat@plt>
mov    %eax,-0x10(%rbp)
jmp    1231 <copen+0xf1>
mov    -0x8(%rbp),%rsi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1040 <IEH3err@plt>
cmpl   $0x0,-0x10(%rbp)
jl     1248 <copen+0x108>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x0,%al
call   1030 <IEH3mbuf@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copen>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
cmp    $0x60,%esi
jg     115c <copen+0x1c>
test   %esi,%esi
je     116b <copen+0x2b>
cmp    $0x1,%esi
je     119f <copen+0x5f>
cmp    $0x2,%esi
je     1182 <copen+0x42>
jmp    11c8 <copen+0x88>
cmp    $0x61,%esi
je     1182 <copen+0x42>
cmp    $0x77,%esi
je     119f <copen+0x5f>
cmp    $0x72,%esi
jne    11c8 <copen+0x88>
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <open@plt>
mov    %eax,%ebp
test   %ebp,%ebp
jns    11ba <copen+0x7a>
jmp    11d9 <copen+0x99>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <open@plt>
test   %eax,%eax
js     119f <copen+0x5f>
mov    %eax,%ebp
mov    $0x2,%r14d
jmp    11ba <copen+0x7a>
mov    %rbx,%rdi
mov    $0x1b6,%esi
xor    %eax,%eax
call   1060 <creat@plt>
mov    %eax,%ebp
mov    $0x1,%r14d
test   %ebp,%ebp
js     11d9 <copen+0x99>
mov    %ebp,%edi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <IEH3mbuf@plt>
jmp    11d9 <copen+0x99>
lea    0xe31(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <IEH3err@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"copen: bad file %s\00"
define i32 @copen(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
switch i32 %6, label %22 [
i32 114, label %7
i32 0, label %8
i32 97, label %11
i32 2, label %12
i32 119, label %18
i32 1, label %19
]
7: ; preds = %2
store i32 0, i32* %4
br label %8
8: ; preds = %2, %7
%9 = load i8*, i8** %3
%10 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %9, i32 0)
store i32 %10, i32* %5
br label %25
11: ; preds = %2
store i32 2, i32* %4
br label %12
12: ; preds = %2, %11
%13 = load i8*, i8** %3
%14 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %13, i32 1)
store i32 %14, i32* %5
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
br label %25
17: ; preds = %12
br label %18
18: ; preds = %2, %17
store i32 1, i32* %4
br label %19
19: ; preds = %2, %18
%20 = load i8*, i8** %3
%21 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @creat to i32 (i8*, i32, ...)*)(i8* %20, i32 438)
store i32 %21, i32* %5
br label %25
22: ; preds = %2
%23 = load i8*, i8** %3
%24 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @IEH3err to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %19, %16, %8
%26 = load i32, i32* %5
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* %5
%30 = load i32, i32* %4
%31 = call i32 (i32, i32, ...) bitcast (i32 (...)* @IEH3mbuf to i32 (i32, i32, ...)*)(i32 %29, i32 %30)
br label %32
32: ; preds = %28, %25
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
@.str = [19 x i8] c"copen: bad file %s\00"
define i32 @copen(i8* %0, i32 %1) {
switch i32 %1, label %10 [
i32 114, label %3
i32 0, label %3
i32 97, label %5
i32 2, label %5
i32 119, label %8
i32 1, label %8
]
3: ; preds = %2, %2
%4 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %0, i32 0)
br label %12
5: ; preds = %2, %2
%6 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %0, i32 1)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %16, label %8
8: ; preds = %2, %5, %2
%9 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @creat to i32 (i8*, i32, ...)*)(i8* %0, i32 438)
br label %12
10: ; preds = %2
%11 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @IEH3err to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %20
12: ; preds = %8, %3
%13 = phi i32 [ 1, %8 ], [ 0, %3 ]
%14 = phi i32 [ %9, %8 ], [ %4, %3 ]
%15 = icmp sgt i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %5, %12
%17 = phi i32 [ %14, %12 ], [ %6, %5 ]
%18 = phi i32 [ %13, %12 ], [ 2, %5 ]
%19 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @IEH3mbuf to i32 (i32, i32, ...)*)(i32 %17, i32 %18)
br label %20
20: ; preds = %10, %16, %12
%21 = phi i32 [ %17, %16 ], [ %14, %12 ], [ undef, %10 ]
ret i32 %21
}