#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*/ ssize_t;
typedef int /*<<< orphan*/ off_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int O_CREAT;
int O_RDONLY;
int O_RDWR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *const);
int open(char *const, int, int);
int /*<<< orphan*/ perror(char *const);
int /*<<< orphan*/ readlockedw(int, int, char *, int, int,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ release(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *const *argv) {
  int res = 1;
  char buffer[1024 + 1];
  ssize_t wres;
  int fd;
  int fdadm;
  off_t off;
  if (argc != 3) {
    fprintf(stderr, "usage: %s inputfile adminfile\n", argv[0]);
    goto RETURN;
  }
  fd = open(argv[1], O_RDONLY, 0666);
  if (fd < 0) {
    perror(argv[1]);
    goto RETURN;
  }
  fdadm = open(argv[2], O_RDWR | O_CREAT, 0666);
  if (fd < 0) {
    perror(argv[2]);
    goto RETURN;
  }
  while ((wres = readlockedw(fd, fdadm, buffer, sizeof(buffer), 500, &off)) >
         0) {
    write(1, buffer, wres);
    release(fdadm, off, wres);
  }
  res = 0;
RETURN:
  exit(res);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11bb <main+0x4b>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4f(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12bc <main+0x14c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
mov    $0x1b6,%edx
call   1060 <open@plt>
mov    %eax,-0x428(%rbp)
cmpl   $0x0,-0x428(%rbp)
jge    11fb <main+0x8b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <perror@plt>
jmp    12bc <main+0x14c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
mov    0x2de5(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1060 <open@plt>
mov    %eax,-0x42c(%rbp)
cmpl   $0x0,-0x428(%rbp)
jge    1244 <main+0xd4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <perror@plt>
jmp    12bc <main+0x14c>
jmp    1249 <main+0xd9>
mov    -0x428(%rbp),%edi
mov    -0x42c(%rbp),%esi
lea    -0x420(%rbp),%rdx
mov    $0x401,%ecx
mov    $0x1f4,%r8d
lea    -0x430(%rbp),%r9
call   1030 <readlockedw@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
jle    12b5 <main+0x145>
lea    -0x420(%rbp),%rsi
mov    -0x424(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
mov    -0x42c(%rbp),%edi
mov    -0x430(%rbp),%esi
mov    -0x424(%rbp),%edx
call   1080 <release@plt>
jmp    1249 <main+0xd9>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11b7 <main+0x47>
mov    0x8(%rbx),%rdi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
mov    $0x1b6,%edx
call   1060 <open@plt>
test   %eax,%eax
jns    11d9 <main+0x69>
mov    0x8(%rbx),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe36(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
mov    0x2df9(%rip),%rax
mov    0x2e0a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1b6,%edx
call   1060 <open@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%r9
mov    %r15d,%edi
mov    %eax,%esi
mov    $0x401,%ecx
mov    $0x1f4,%r8d
call   1030 <readlockedw@plt>
xor    %r14d,%r14d
test   %eax,%eax
jle    126d <main+0xfd>
mov    %eax,%ebx
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%r12
mov    $0x1,%edi
mov    %r13,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
mov    0xc(%rsp),%esi
mov    %ebp,%edi
mov    %ebx,%edx
call   1080 <release@plt>
mov    %r15d,%edi
mov    %ebp,%esi
mov    %r13,%rdx
mov    $0x401,%ecx
mov    $0x1f4,%r8d
mov    %r12,%r9
call   1030 <readlockedw@plt>
mov    %eax,%ebx
test   %eax,%eax
jg     1230 <main+0xc0>
mov    %r14d,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"usage: %s inputfile adminfile\0A\00"
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1025 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %64
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_RDONLY
%25 = call i32 @open(i8* %23, i32 %24, i32 438)
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %20
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @perror(i8* %31)
br label %64
33: ; preds = %20
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = load i32, i32* @O_RDWR
%38 = load i32, i32* @O_CREAT
%39 = or i32 %37, %38
%40 = call i32 @open(i8* %36, i32 %39, i32 438)
store i32 %40, i32* %10
%41 = load i32, i32* %9
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %33
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @perror(i8* %46)
br label %64
48: ; preds = %33
br label %49
49: ; preds = %55, %48
%50 = load i32, i32* %9
%51 = load i32, i32* %10
%52 = getelementptr inbounds [1025 x i8], [1025 x i8]* %7, i64 0, i64 0
%53 = call i32 @readlockedw(i32 %50, i32 %51, i8* %52, i32 1025, i32 500, i32* %11)
store i32 %53, i32* %8
%54 = icmp sgt i32 %53, 0
br i1 %54, label %55, label %63
55: ; preds = %49
%56 = getelementptr inbounds [1025 x i8], [1025 x i8]* %7, i64 0, i64 0
%57 = load i32, i32* %8
%58 = call i32 @write(i32 1, i8* %56, i32 %57)
%59 = load i32, i32* %10
%60 = load i32, i32* %11
%61 = load i32, i32* %8
%62 = call i32 @release(i32 %59, i32 %60, i32 %61)
br label %49
63: ; preds = %49
store i32 0, i32* %6
br label %64
64: ; preds = %63, %43, %28, %14
%65 = load i32, i32* %6
%66 = call i32 @exit(i32 %65)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"usage: %s inputfile adminfile\0A\00"
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1025 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [1025 x i8], [1025 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %0, 3
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %37
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 @open(i8* %14, i32 %15, i32 438)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i8*, i8** %13
%20 = tail call i32 @perror(i8* %19)
br label %37
21: ; preds = %12
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_RDWR
%25 = load i32, i32* @O_CREAT
%26 = or i32 %25, %24
%27 = tail call i32 @open(i8* %23, i32 %26, i32 438)
%28 = call i32 @readlockedw(i32 %16, i32 %27, i8* %5, i32 1025, i32 500, i32* %4)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %21, %30
%31 = phi i32 [ %35, %30 ], [ %28, %21 ]
%32 = call i32 @write(i32 1, i8* %5, i32 %31)
%33 = load i32, i32* %4
%34 = call i32 @release(i32 %27, i32 %33, i32 %31)
%35 = call i32 @readlockedw(i32 %16, i32 %27, i8* %5, i32 1025, i32 500, i32* %4)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %30, label %37
37: ; preds = %30, %21, %18, %8
%38 = phi i32 [ 1, %8 ], [ 1, %18 ], [ 0, %21 ], [ 0, %30 ]
%39 = call i32 @exit(i32 %38)
unreachable
}