#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int O_EXCL;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fstat(int, struct stat *);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int read(int, void *, int);
int /*<<< orphan*/ stderr;
int write(int, void *, int);
int main(int argc, char *argv[]) {
  int fd_in, fd_out;
  if (argc != 3) {
    fprintf(stderr, "usage: %s IN_FILE OUT_FILE\n", argv[0]);
    return EXIT_FAILURE;
  }
  if ((fd_in = open(argv[1], O_RDONLY)) == -1) {
    perror("unable to open input file for reading");
    return EXIT_FAILURE;
  }
  struct stat st;
  if (fstat(fd_in, &st) == -1) {
    perror("unable to retrieve information");
    return EXIT_FAILURE;
  }
  if (!S_ISREG(st.st_mode)) {
    fprintf(stderr, "not a regular file: %s\n", argv[1]);
    return EXIT_FAILURE;
  }
  if ((fd_out = open(argv[2], O_WRONLY | O_CREAT | O_EXCL, 0644)) == -1) {
    perror("unable to open output file for writing");
    return EXIT_FAILURE;
  }
  char buf[32];
  int siz;
  do {
    siz = read(fd_in, (void *)buf, 32);
    if (siz == -1) {
      perror("error while reading");
      return EXIT_FAILURE;
    }
    if (write(fd_out, (void *)buf, siz) == -1) {
      perror("error while writing");
      return EXIT_FAILURE;
    }
  } while (siz == 32);
  close(fd_in);
  close(fd_out);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11cd <main+0x4d>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1377 <main+0x1f7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    120e <main+0x8e>
lea    0xe24(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1377 <main+0x1f7>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10a0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1240 <main+0xc0>
lea    0xe18(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1377 <main+0x1f7>
mov    -0x20(%rbp),%edi
call   1070 <S_ISREG@plt>
cmp    $0x0,%eax
jne    127f <main+0xff>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdf8(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1377 <main+0x1f7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d1a(%rip),%rax
mov    (%rax),%esi
mov    0x2d61(%rip),%rax
or     (%rax),%esi
mov    0x2d28(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    12d7 <main+0x157>
lea    0xdb8(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cf3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1377 <main+0x1f7>
jmp    12dc <main+0x15c>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   1050 <read@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    1317 <main+0x197>
lea    0xd9f(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cb3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1377 <main+0x1f7>
mov    -0x18(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    134c <main+0x1cc>
lea    0xd7e(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1377 <main+0x1f7>
jmp    1351 <main+0x1d1>
cmpl   $0x20,-0x44(%rbp)
je     12dc <main+0x15c>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    0x2c46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jne    126f <main+0xef>
mov    0x8(%r14),%rdi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     12b1 <main+0x131>
mov    %eax,%r15d
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10a0 <fstat@plt>
cmp    $0xffffffff,%eax
je     12ba <main+0x13a>
mov    0x8(%rsp),%edi
call   1070 <S_ISREG@plt>
test   %eax,%eax
je     1284 <main+0x104>
mov    0x2dc5(%rip),%rax
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%r14),%rdi
mov    0x2dcf(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
xor    %eax,%eax
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     12c3 <main+0x143>
mov    %eax,%r14d
lea    0x10(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     12cc <main+0x14c>
mov    %eax,%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     12d5 <main+0x155>
cmp    $0x20,%ebp
je     1220 <main+0xa0>
mov    %r15d,%edi
call   1040 <close@plt>
mov    %r14d,%edi
call   1040 <close@plt>
mov    0x2d4b(%rip),%rax
jmp    12a4 <main+0x124>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd7e(%rip),%rsi
jmp    1298 <main+0x118>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xdc9(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd64(%rip),%rdi
jmp    12dc <main+0x15c>
lea    0xd81(%rip),%rdi
jmp    12dc <main+0x15c>
lea    0xdaf(%rip),%rdi
jmp    12dc <main+0x15c>
lea    0xdcd(%rip),%rdi
jmp    12dc <main+0x15c>
lea    0xdd8(%rip),%rdi
call   1090 <perror@plt>
jmp    129d <main+0x11d>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"usage: %s IN_FILE OUT_FILE\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [38 x i8] c"unable to open input file for reading\00"
@.str.2 = [31 x i8] c"unable to retrieve information\00"
@.str.3 = [24 x i8] c"not a regular file: %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.4 = [39 x i8] c"unable to open output file for writing\00"
@.str.5 = [20 x i8] c"error while reading\00"
@.str.6 = [20 x i8] c"error while writing\00"
@EXIT_SUCCESS = 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 %struct.stat
%9 = alloca [32 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %3
br label %92
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 (i8*, i32, ...) @open(i8* %23, i32 %24)
store i32 %25, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %3
br label %92
30: ; preds = %20
%31 = load i32, i32* %6
%32 = call i32 @fstat(i32 %31, %struct.stat* %8)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
store i32 %36, i32* %3
br label %92
37: ; preds = %30
%38 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @S_ISREG(i32 %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %49, label %42
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
store i32 %48, i32* %3
br label %92
49: ; preds = %37
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = load i32, i32* @O_WRONLY
%54 = load i32, i32* @O_CREAT
%55 = or i32 %53, %54
%56 = load i32, i32* @O_EXCL
%57 = or i32 %55, %56
%58 = call i32 (i8*, i32, ...) @open(i8* %52, i32 %57, i32 420)
store i32 %58, i32* %7
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %63
60: ; preds = %49
%61 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
store i32 %62, i32* %3
br label %92
63: ; preds = %49
br label %64
64: ; preds = %83, %63
%65 = load i32, i32* %6
%66 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%67 = call i32 @read(i32 %65, i8* %66, i32 32)
store i32 %67, i32* %10
%68 = load i32, i32* %10
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %73
70: ; preds = %64
%71 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%72 = load i32, i32* @EXIT_FAILURE
store i32 %72, i32* %3
br label %92
73: ; preds = %64
%74 = load i32, i32* %7
%75 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%76 = load i32, i32* %10
%77 = call i32 @write(i32 %74, i8* %75, i32 %76)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %82
79: ; preds = %73
%80 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%81 = load i32, i32* @EXIT_FAILURE
store i32 %81, i32* %3
br label %92
82: ; preds = %73
br label %83
83: ; preds = %82
%84 = load i32, i32* %10
%85 = icmp eq i32 %84, 32
br i1 %85, label %64, label %86
86: ; preds = %83
%87 = load i32, i32* %6
%88 = call i32 @close(i32 %87)
%89 = load i32, i32* %7
%90 = call i32 @close(i32 %89)
%91 = load i32, i32* @EXIT_SUCCESS
store i32 %91, i32* %3
br label %92
92: ; preds = %86, %79, %70, %60, %42, %34, %27, %13
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"usage: %s IN_FILE OUT_FILE\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [38 x i8] c"unable to open input file for reading\00"
@.str.2 = [31 x i8] c"unable to retrieve information\00"
@.str.3 = [24 x i8] c"not a regular file: %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.4 = [39 x i8] c"unable to open output file for writing\00"
@.str.5 = [20 x i8] c"error while reading\00"
@.str.6 = [20 x i8] c"error while writing\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca [32 x i8]
%5 = icmp eq i32 %0, 3
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
br label %72
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 (i8*, i32, ...) @open(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = tail call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
br label %72
20: ; preds = %11
%21 = bitcast %struct.stat* %3 to i8*
%22 = call i32 @fstat(i32 %15, %struct.stat* %3)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
br label %70
27: ; preds = %20
%28 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%29 = load i32, i32* %28
%30 = tail call i32 @S_ISREG(i32 %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %12
%35 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @EXIT_FAILURE
br label %70
37: ; preds = %27
%38 = getelementptr inbounds i8*, i8** %1, i64 2
%39 = load i8*, i8** %38
%40 = load i32, i32* @O_WRONLY
%41 = load i32, i32* @O_CREAT
%42 = or i32 %41, %40
%43 = load i32, i32* @O_EXCL
%44 = or i32 %42, %43
%45 = tail call i32 (i8*, i32, ...) @open(i8* %39, i32 %44, i32 420)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %37
%48 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
br label %70
50: ; preds = %37
%51 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
br label %52
52: ; preds = %62, %50
%53 = call i32 @read(i32 %15, i8* %51, i32 32)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %67
57: ; preds = %52
%58 = call i32 @write(i32 %45, i8* %51, i32 %53)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %62
60: ; preds = %57
%61 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %67
62: ; preds = %57
%63 = icmp eq i32 %53, 32
br i1 %63, label %52, label %64
64: ; preds = %62
%65 = tail call i32 @close(i32 %15)
%66 = tail call i32 @close(i32 %45)
br label %67
67: ; preds = %64, %60, %55
%68 = phi i32* [ @EXIT_FAILURE, %55 ], [ @EXIT_FAILURE, %60 ], [ @EXIT_SUCCESS, %64 ]
%69 = load i32, i32* %68
br label %70
70: ; preds = %67, %47, %32, %24
%71 = phi i32 [ %26, %24 ], [ %49, %47 ], [ %69, %67 ], [ %36, %32 ]
br label %72
72: ; preds = %70, %17, %6
%73 = phi i32 [ %10, %6 ], [ %19, %17 ], [ %71, %70 ]
ret i32 %73
}