#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 EX_USAGE;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ asprintf(char **, char *, char *, char const *);
int copy_file(char *, char *, unsigned int);
int getopt(int, char *const *, char *);
scalar_t__ optind;
int /*<<< orphan*/ printf(char *);
scalar_t__ stat(char *, struct stat *);
char *strrchr(char *, char);
int main(int argc, char *const argv[]) {
  struct stat statbuf;
  char *src, *dst;
  unsigned flags = 0;
  int opt;
  while ((opt = getopt(argc, argv, "ogOGma")) != -1) {
    switch (opt) {
    case 'o':
      flags |= 0x0002;
      break;
    case 'O':
      flags |= 0x0004;
      break;
    case 'g':
      flags |= 0x0001;
      break;
    case 'G':
      flags |= 0x0020;
      break;
    case 'm':
      flags |= 0x0008;
      break;
    case 'a':
      flags |= 0x0010;
      break;
    }
  }
  if (argc < 2) {
    printf("usage: cpx [-ogmaOG] SRC DST\n");
    return EX_USAGE;
  }
  argc -= optind;
  argv += optind;
  src = (char *)argv[0];
  dst = (char *)argv[1];
  if (stat(dst, &statbuf) == 0 && S_ISDIR(statbuf.st_mode)) {
    const char *fname = strrchr(src, '/') + 1;
    asprintf(&dst, "%s/%s", dst, fname);
  }
  return copy_file(src, dst, flags);
}


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)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xf09(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
je     1229 <main+0xb9>
mov    -0x30(%rbp),%eax
add    $0xffffffb9,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x28,%eax
ja     1224 <main+0xb4>
mov    -0x40(%rbp),%rax
lea    0xe34(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x2c(%rbp),%eax
or     $0x2,%eax
mov    %eax,-0x2c(%rbp)
jmp    1224 <main+0xb4>
mov    -0x2c(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0x2c(%rbp)
jmp    1224 <main+0xb4>
mov    -0x2c(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1224 <main+0xb4>
mov    -0x2c(%rbp),%eax
or     $0x20,%eax
mov    %eax,-0x2c(%rbp)
jmp    1224 <main+0xb4>
mov    -0x2c(%rbp),%eax
or     $0x8,%eax
mov    %eax,-0x2c(%rbp)
jmp    1224 <main+0xb4>
mov    -0x2c(%rbp),%eax
or     $0x10,%eax
mov    %eax,-0x2c(%rbp)
jmp    118d <main+0x1d>
cmpl   $0x2,-0x8(%rbp)
jge    1250 <main+0xe0>
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12fb <main+0x18b>
mov    0x2d89(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2d75(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jne    12e8 <main+0x178>
mov    -0x18(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     12e8 <main+0x178>
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    0xde6(%rip),%rsi
call   1080 <asprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <copy_file@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r14d,%r14d
lea    0xf19(%rip),%r15
lea    0xe6e(%rip),%r12
jmp    11a5 <main+0x35>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0xffffffff,%eax
je     11e7 <main+0x77>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <getopt@plt>
lea    -0x47(%rax),%ecx
cmp    $0x28,%ecx
ja     11a0 <main+0x30>
movslq (%r12,%rcx,4),%rax
add    %r12,%rax
jmp    *%rax
or     $0x20,%r14d
jmp    11a5 <main+0x35>
or     $0x4,%r14d
jmp    11a5 <main+0x35>
or     $0x10,%r14d
jmp    11a5 <main+0x35>
or     $0x1,%r14d
jmp    11a5 <main+0x35>
or     $0x8,%r14d
jmp    11a5 <main+0x35>
or     $0x2,%r14d
jmp    11a5 <main+0x35>
cmp    $0x1,%ebp
jg     1203 <main+0x93>
lea    0xebe(%rip),%rdi
call   1040 <puts@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
jmp    1270 <main+0x100>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rax
mov    (%rbx,%rax,8),%rbp
mov    0x8(%rbx,%rax,8),%rbx
mov    %rbx,0x8(%rsp)
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <stat@plt>
test   %rax,%rax
jne    1262 <main+0xf2>
mov    (%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %rax,%rax
je     1262 <main+0xf2>
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
lea    0x1(%rax),%rcx
lea    0xe5b(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %rbx,%rdx
call   1080 <asprintf@plt>
mov    0x8(%rsp),%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <copy_file@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [7 x i8] c"ogOGma\00"
@.str.1 = [30 x i8] c"usage: cpx [-ogmaOG] SRC DST\0A\00"
@EX_USAGE = global i32 0
@optind = global i64 0
@.str.2 = [6 x i8] c"%s/%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
br label %12
12: ; preds = %37, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %10
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %38
17: ; preds = %12
%18 = load i32, i32* %10
switch i32 %18, label %37 [
i32 111, label %19
i32 79, label %22
i32 103, label %25
i32 71, label %28
i32 109, label %31
i32 97, label %34
]
19: ; preds = %17
%20 = load i32, i32* %9
%21 = or i32 %20, 2
store i32 %21, i32* %9
br label %37
22: ; preds = %17
%23 = load i32, i32* %9
%24 = or i32 %23, 4
store i32 %24, i32* %9
br label %37
25: ; preds = %17
%26 = load i32, i32* %9
%27 = or i32 %26, 1
store i32 %27, i32* %9
br label %37
28: ; preds = %17
%29 = load i32, i32* %9
%30 = or i32 %29, 32
store i32 %30, i32* %9
br label %37
31: ; preds = %17
%32 = load i32, i32* %9
%33 = or i32 %32, 8
store i32 %33, i32* %9
br label %37
34: ; preds = %17
%35 = load i32, i32* %9
%36 = or i32 %35, 16
store i32 %36, i32* %9
br label %37
37: ; preds = %17, %34, %31, %28, %25, %22, %19
br label %12
38: ; preds = %12
%39 = load i32, i32* %4
%40 = icmp slt i32 %39, 2
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32, i32* @EX_USAGE
store i32 %43, i32* %3
br label %79
44: ; preds = %38
%45 = load i64, i64* @optind
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = sub nsw i64 %47, %45
%49 = trunc i64 %48 to i32
store i32 %49, i32* %4
%50 = load i64, i64* @optind
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 %50
store i8** %52, i8*** %5
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 0
%55 = load i8*, i8** %54
store i8* %55, i8** %7
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
store i8* %58, i8** %8
%59 = load i8*, i8** %8
%60 = call i64 @stat(i8* %59, %struct.stat* %6)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %74
62: ; preds = %44
%63 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%64 = load i32, i32* %63
%65 = call i64 @S_ISDIR(i32 %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %74
67: ; preds = %62
%68 = load i8*, i8** %7
%69 = call i8* @strrchr(i8* %68, i8 signext 47)
%70 = getelementptr inbounds i8, i8* %69, i64 1
store i8* %70, i8** %11
%71 = load i8*, i8** %8
%72 = load i8*, i8** %11
%73 = call i32 @asprintf(i8** %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %71, i8* %72)
br label %74
74: ; preds = %67, %62, %44
%75 = load i8*, i8** %7
%76 = load i8*, i8** %8
%77 = load i32, i32* %9
%78 = call i32 @copy_file(i8* %75, i8* %76, i32 %77)
store i32 %78, i32* %3
br label %79
79: ; preds = %74, %41
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [7 x i8] c"ogOGma\00"
@EX_USAGE = global i32 0
@optind = global i64 0
@.str.2 = [6 x i8] c"%s/%s\00"
@str = [29 x i8] c"usage: cpx [-ogmaOG] SRC DST\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = alloca i8*
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast i8** %4 to i8*
br label %7
7: ; preds = %23, %2
%8 = phi i32 [ 0, %2 ], [ %24, %23 ]
br label %9
9: ; preds = %7, %9
%10 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
switch i32 %10, label %9 [
i32 -1, label %25
i32 111, label %11
i32 79, label %13
i32 103, label %15
i32 71, label %17
i32 109, label %19
i32 97, label %21
]
11: ; preds = %9
%12 = or i32 %8, 2
br label %23
13: ; preds = %9
%14 = or i32 %8, 4
br label %23
15: ; preds = %9
%16 = or i32 %8, 1
br label %23
17: ; preds = %9
%18 = or i32 %8, 32
br label %23
19: ; preds = %9
%20 = or i32 %8, 8
br label %23
21: ; preds = %9
%22 = or i32 %8, 16
br label %23
23: ; preds = %21, %19, %17, %15, %13, %11
%24 = phi i32 [ %12, %11 ], [ %14, %13 ], [ %16, %15 ], [ %18, %17 ], [ %20, %19 ], [ %22, %21 ]
br label %7
25: ; preds = %9
%26 = icmp slt i32 %0, 2
br i1 %26, label %27, label %30
27: ; preds = %25
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%29 = load i32, i32* @EX_USAGE
br label %51
30: ; preds = %25
%31 = load i64, i64* @optind
%32 = getelementptr inbounds i8*, i8** %1, i64 %31
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8*, i8** %32, i64 1
%35 = load i8*, i8** %34
store i8* %35, i8** %4
%36 = call i64 @stat(i8* %35, %struct.stat* %3)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %30
%39 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%40 = load i32, i32* %39
%41 = call i64 @S_ISDIR(i32 %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %48, label %43
43: ; preds = %38
%44 = call i8* @strrchr(i8* dereferenceable(1) %33, i8 signext 47)
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* %45)
%47 = load i8*, i8** %4
br label %48
48: ; preds = %43, %38, %30
%49 = phi i8* [ %47, %43 ], [ %35, %38 ], [ %35, %30 ]
%50 = call i32 @copy_file(i8* %33, i8* %49, i32 %8)
br label %51
51: ; preds = %48, %27
%52 = phi i32 [ %29, %27 ], [ %50, %48 ]
ret i32 %52
}