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

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ minix_create(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ minix_mount(char *);
int /*<<< orphan*/ minix_umount();
int /*<<< orphan*/ minix_write(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int /*<<< orphan*/ sclose(int);
char *smalloc(int /*<<< orphan*/);
int sopen(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ sread(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ sstat(char const *, struct stat *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int fd;
  struct stat stbuf;
  char *buf;
  const char *src, *dest;
  uint16_t num;
  if (argc != 4)
    usage();
  src = argv[2];
  dest = argv[3];
  sstat(src, &stbuf);
  buf = smalloc(stbuf.st_size);
  minix_mount(argv[1]);
  fd = sopen(src, O_RDONLY);
  sread(fd, buf, stbuf.st_size);
  sclose(fd);
  num = minix_create(dest, stbuf.st_mode);
  minix_write(num, buf, stbuf.st_size);
  minix_umount();
  free(buf);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11d7 <main+0x27>
mov    $0x0,%al
call   10c0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10a0 <sstat@plt>
mov    -0x20(%rbp),%edi
call   10d0 <smalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <minix_mount@plt>
mov    -0x30(%rbp),%rdi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
call   1060 <sopen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1090 <sread@plt>
mov    -0x14(%rbp),%edi
call   1050 <sclose@plt>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <minix_create@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   10b0 <minix_write@plt>
mov    $0x0,%al
call   1040 <minix_umount@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x4,%edi
je     11c7 <main+0x17>
xor    %eax,%eax
call   10c0 <usage@plt>
mov    0x10(%rbx),%r12
mov    0x18(%rbx),%r14
mov    %rsp,%rsi
mov    %r12,%rdi
call   10a0 <sstat@plt>
mov    (%rsp),%edi
call   10d0 <smalloc@plt>
mov    %rax,%r15
mov    0x8(%rbx),%rdi
call   1080 <minix_mount@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   1060 <sopen@plt>
mov    %eax,%ebx
mov    (%rsp),%edx
mov    %eax,%edi
mov    %r15,%rsi
call   1090 <sread@plt>
mov    %ebx,%edi
call   1050 <sclose@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1070 <minix_create@plt>
mov    (%rsp),%edx
mov    %eax,%edi
mov    %r15,%rsi
call   10b0 <minix_write@plt>
xor    %eax,%eax
call   1040 <minix_umount@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@O_RDONLY = global i32 0
@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 %struct.stat
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (...) @usage()
br label %16
16: ; preds = %14, %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
store i8* %19, i8** %9
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21
store i8* %22, i8** %10
%23 = load i8*, i8** %9
%24 = call i32 @sstat(i8* %23, %struct.stat* %7)
%25 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i8* @smalloc(i32 %26)
store i8* %27, i8** %8
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @minix_mount(i8* %30)
%32 = load i8*, i8** %9
%33 = load i32, i32* @O_RDONLY
%34 = call i32 @sopen(i8* %32, i32 %33)
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = load i8*, i8** %8
%37 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 @sread(i32 %35, i8* %36, i32 %38)
%40 = load i32, i32* %6
%41 = call i32 @sclose(i32 %40)
%42 = load i8*, i8** %10
%43 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%44 = load i32, i32* %43
%45 = call i32 @minix_create(i8* %42, i32 %44)
store i32 %45, i32* %11
%46 = load i32, i32* %11
%47 = load i8*, i8** %8
%48 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i32 @minix_write(i32 %46, i8* %47, i32 %49)
%51 = call i32 (...) @minix_umount()
%52 = load i8*, i8** %8
%53 = call i32 @free(i8* %52)
%54 = load i32, i32* @EXIT_SUCCESS
ret i32 %54
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@O_RDONLY = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 4
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (...) @usage()
br label %8
8: ; preds = %6, %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 3
%12 = load i8*, i8** %11
%13 = call i32 @sstat(i8* %10, %struct.stat* %3)
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%15 = load i32, i32* %14
%16 = call i8* @smalloc(i32 %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @minix_mount(i8* %18)
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @sopen(i8* %10, i32 %20)
%22 = load i32, i32* %14
%23 = call i32 @sread(i32 %21, i8* %16, i32 %22)
%24 = call i32 @sclose(i32 %21)
%25 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%26 = load i32, i32* %25
%27 = call i32 @minix_create(i8* %12, i32 %26)
%28 = load i32, i32* %14
%29 = call i32 @minix_write(i32 %27, i8* %16, i32 %28)
%30 = call i32 (...) @minix_umount()
%31 = call i32 @free(i8* %16)
%32 = load i32, i32* @EXIT_SUCCESS
ret i32 %32
}