#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 */

/* Variables and functions */
int /*<<< orphan*/ F_RDLCK;
int /*<<< orphan*/ F_UNLCK;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ lock_operation(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int ac, char *av[]) {
  int fd, nread;
  char buf[10];
  if (ac != 2) {
    fprintf(stderr, "useage:file_tc filename\n");
    exit(1);
  }
  if ((fd = open(av[1], O_RDONLY)) == -1) {
    perror(av[1]);
    exit(3);
  };
  lock_operation(fd, F_RDLCK);
  while ((nread = read(fd, buf, 10)) > 0)
    write(1, buf, nread);
  lock_operation(fd, F_UNLCK);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11bf <main+0x3f>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11f8 <main+0x78>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <perror@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
call   1050 <lock_operation@plt>
mov    -0x14(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0xa,%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    123c <main+0xbc>
lea    -0x22(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    1209 <main+0x89>
mov    -0x14(%rbp),%edi
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
call   1050 <lock_operation@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    1222 <main+0xa2>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1241 <main+0xc1>
mov    %eax,%ebp
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1050 <lock_operation@plt>
lea    0xe(%rsp),%rsi
mov    %ebp,%edi
mov    $0xa,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    1202 <main+0x82>
lea    0xe(%rsp),%rbx
nopl   0x0(%rax)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1060 <read@plt>
test   %eax,%eax
jg     11e0 <main+0x60>
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1050 <lock_operation@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x8(%rbx),%rdi
call   1090 <perror@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"useage:file_tc filename\0A\00"
@O_RDONLY = global i32 0
@F_RDLCK = global i32 0
@F_UNLCK = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %6
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @perror(i8* %25)
%27 = call i32 @exit(i32 3)
unreachable
28: ; preds = %15
%29 = load i32, i32* %6
%30 = load i32, i32* @F_RDLCK
%31 = call i32 @lock_operation(i32 %29, i32 %30)
br label %32
32: ; preds = %37, %28
%33 = load i32, i32* %6
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%35 = call i32 @read(i32 %33, i8* %34, i32 10)
store i32 %35, i32* %7
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%39 = load i32, i32* %7
%40 = call i32 @write(i32 1, i8* %38, i32 %39)
br label %32
41: ; preds = %32
%42 = load i32, i32* %6
%43 = load i32, i32* @F_UNLCK
%44 = call i32 @lock_operation(i32 %42, i32 %43)
%45 = load i32, i32* %6
%46 = call i32 @close(i32 %45)
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"useage:file_tc filename\0A\00"
@O_RDONLY = global i32 0
@F_RDLCK = global i32 0
@F_UNLCK = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load i8*, i8** %11
%18 = tail call i32 @perror(i8* %17)
%19 = tail call i32 @exit(i32 3)
unreachable
20: ; preds = %10
%21 = load i32, i32* @F_RDLCK
%22 = tail call i32 @lock_operation(i32 %14, i32 %21)
%23 = call i32 @read(i32 %14, i8* %4, i32 10)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %20, %25
%26 = phi i32 [ %28, %25 ], [ %23, %20 ]
%27 = call i32 @write(i32 1, i8* %4, i32 %26)
%28 = call i32 @read(i32 %14, i8* %4, i32 10)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %25, label %30
30: ; preds = %25, %20
%31 = load i32, i32* @F_UNLCK
%32 = tail call i32 @lock_operation(i32 %14, i32 %31)
%33 = tail call i32 @close(i32 %14)
ret i32 0
}