#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  char buf[16];
  int rfd, wfd;
  ssize_t ret, wret;
  rfd = open(argv[1], O_RDONLY);
  do {
    if (rfd == -1) {
      perror("open");
      exit(1);
    }
  } while (0);
  wfd = creat(argv[2], 0644);
  do {
    if (wfd == -1) {
      perror("create");
      exit(1);
    }
  } while (0);
  while ((ret = read(rfd, buf, 16)) > 0) {
    printf(".");
    wret = write(wfd, buf, ret);
    do {
      if (wret == -1) {
        perror("write");
        exit(1);
      }
    } while (0);
  }
  do {
    if (ret == -1) {
      perror("read");
      exit(1);
    }
  } while (0);
  printf(" finish\n");
  close(rfd);
  close(wfd);
  return 0;
}


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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11cf <main+0x4f>
lea    0xe40(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    11d4 <main+0x54>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x1a4,%esi
call   1090 <creat@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1209 <main+0x89>
lea    0xe0b(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    120e <main+0x8e>
jmp    1213 <main+0x93>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1060 <read@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jle    1278 <main+0xf8>
lea    0xdd5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    126e <main+0xee>
lea    0xdaf(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1273 <main+0xf3>
jmp    1213 <main+0x93>
jmp    127d <main+0xfd>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    129d <main+0x11d>
lea    0xd86(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12a2 <main+0x122>
lea    0xd70(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1256 <main+0xc6>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
mov    $0x1a4,%esi
call   10a0 <creat@plt>
cmp    $0xffffffff,%eax
je     125f <main+0xcf>
mov    %eax,%r15d
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1070 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1228 <main+0x98>
mov    $0x2e,%edi
call   1030 <putchar@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
jne    11e0 <main+0x50>
lea    0xdf3(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
cmp    $0xffffffff,%ebp
je     1268 <main+0xd8>
lea    0xde3(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    %r15d,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda3(%rip),%rdi
jmp    1219 <main+0x89>
lea    0xd9f(%rip),%rdi
jmp    1219 <main+0x89>
lea    0xda3(%rip),%rdi
jmp    1219 <main+0x89>

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

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [7 x i8] c"create\00"
@.str.3 = [6 x i8] c"write\00"
@.str.4 = [5 x i8] c"read\00"
@str = [8 x i8] c" finish\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @creat(i8* %15, i32 420)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %13, %24
%22 = call i32 @read(i32 %8, i8* %4, i32 16)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = tail call i32 @putchar(i32 46)
%26 = call i32 @write(i32 %16, i8* %4, i32 %22)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %21
28: ; preds = %24
%29 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %21
%32 = icmp eq i32 %22, -1
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %31
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%38 = tail call i32 @close(i32 %8)
%39 = tail call i32 @close(i32 %16)
ret i32 0
}