#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;
};
typedef int /*<<< orphan*/ p;
typedef int /*<<< orphan*/ mode_t;

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ cp_dir(char *, char *);
int /*<<< orphan*/ cp_file(char *, char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int lstat(char *, struct stat *);
char *malloc(scalar_t__);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ mkdir(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
scalar_t__ strlen(char *);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "%s src dest\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  mode_t oldmask = umask(0);
  struct stat buf;
  struct stat bufdest;
  if (lstat(argv[1], &buf) == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day03/mycp.c",
              91, "lstat", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  if (S_ISREG(buf.st_mode)) {
    if (lstat(argv[2], &bufdest) == -1) {
      if (errno == ENOENT) {
        cp_file(argv[1], argv[2], buf.st_mode);
      } else
        do {
          fprintf(stderr, "[%s][%d]:%s %s\n",
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/"
                  "heads/master/apue/day03/mycp.c",
                  100, "lstat", strerror(errno));
          exit(EXIT_FAILURE);
        } while (0);
    } else {
      if (S_ISDIR(bufdest.st_mode)) {
        char *p = malloc(strlen(argv[2]) + 1 + strlen(argv[1]) + 1);
        memset(p, 0x00, sizeof(p));
        sprintf(p, "%s/%s", argv[2], argv[1]);
        cp_file(argv[1], p, buf.st_mode);
      } else {
        char c;
        printf("file %s exist, do you want overwrite ? y/n", argv[2]);
        scanf(" %c", &c);
        if (c == 'y' || c == 'Y') {
          unlink(argv[2]);
          cp_file(argv[1], argv[2], buf.st_mode);
        }
      }
    }
  } else if (S_ISDIR(buf.st_mode)) {
    if (lstat(argv[2], &bufdest) == -1) {
      if (errno == ENOENT) {
        mkdir(argv[2], buf.st_mode);
        cp_dir(argv[1], argv[2]);
      }
    } else if (S_ISREG(bufdest.st_mode)) {
      printf("%s is a file!\n", argv[2]);
      exit(EXIT_FAILURE);
    } else if (S_ISDIR(bufdest.st_mode)) {
      char *p = malloc(strlen(argv[2]) + 1 + strlen(argv[1]) + 1);
      memset(p, 0x00, sizeof(p));
      sprintf(p, "%s/%s", argv[2], argv[1]);
      mkdir(p, buf.st_mode);
      cp_dir(argv[1], p);
    }
  }
  umask(oldmask);
  return 0;
}


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     125c <main+0x4c>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
xor    %edi,%edi
call   10b0 <umask@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <lstat@plt>
cmp    $0xffffffff,%eax
jne    12d5 <main+0xc5>
jmp    1285 <main+0x75>
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%rdi
call   1130 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%r9
lea    0xd60(%rip),%rsi
lea    0xd69(%rip),%rdx
mov    $0x5b,%ecx
lea    0xdf0(%rip),%r8
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0x18(%rbp),%edi
call   10d0 <S_ISREG@plt>
cmp    $0x0,%rax
je     1495 <main+0x285>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <lstat@plt>
cmp    $0xffffffff,%eax
jne    1392 <main+0x182>
mov    0x2cd0(%rip),%rax
mov    (%rax),%rax
mov    0x2cae(%rip),%rcx
cmp    (%rcx),%rax
jne    1338 <main+0x128>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x18(%rbp),%edx
call   10f0 <cp_file@plt>
jmp    138d <main+0x17d>
jmp    133d <main+0x12d>
mov    0x2c9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2c88(%rip),%rax
mov    (%rax),%rdi
call   1130 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%r9
lea    0xca8(%rip),%rsi
lea    0xcb1(%rip),%rdx
mov    $0x64,%ecx
lea    0xd38(%rip),%r8
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2c4a(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
jmp    1490 <main+0x280>
mov    -0x20(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1423 <main+0x213>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   10e0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xcb1(%rip),%rsi
call   1110 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   10f0 <cp_file@plt>
jmp    148b <main+0x27b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xc8a(%rip),%rdi
call   1060 <printf@plt>
lea    0xca9(%rip),%rdi
lea    -0x29(%rbp),%rsi
call   1100 <scanf@plt>
movsbl -0x29(%rbp),%eax
cmp    $0x79,%eax
je     1461 <main+0x251>
movsbl -0x29(%rbp),%eax
cmp    $0x59,%eax
jne    1486 <main+0x276>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <unlink@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x18(%rbp),%edx
call   10f0 <cp_file@plt>
jmp    148b <main+0x27b>
jmp    1490 <main+0x280>
jmp    15e2 <main+0x3d2>
mov    -0x18(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
je     15dd <main+0x3cd>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <lstat@plt>
cmp    $0xffffffff,%eax
jne    1505 <main+0x2f5>
mov    0x2b10(%rip),%rax
mov    (%rax),%rax
mov    0x2aee(%rip),%rcx
cmp    (%rcx),%rax
jne    1500 <main+0x2f0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x18(%rbp),%esi
call   1040 <mkdir@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   10c0 <cp_dir@plt>
jmp    15d8 <main+0x3c8>
mov    -0x20(%rbp),%edi
call   10d0 <S_ISREG@plt>
cmp    $0x0,%rax
je     1539 <main+0x329>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xbc5(%rip),%rdi
call   1060 <printf@plt>
mov    0x2a9e(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0x20(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
je     15ce <main+0x3be>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   10e0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xb0a(%rip),%rsi
call   1110 <sprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1040 <mkdir@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x38(%rbp),%rsi
call   10c0 <cp_dir@plt>
jmp    15d3 <main+0x3c3>
jmp    15d8 <main+0x3c8>
jmp    15dd <main+0x3cd>
jmp    15e2 <main+0x3d2>
mov    -0x14(%rbp),%edi
call   10b0 <umask@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1461 <main+0x251>
xor    %edi,%edi
call   10b0 <umask@plt>
mov    %eax,%r14d
mov    0x8(%rbx),%rdi
lea    0x18(%rsp),%rsi
call   1090 <lstat@plt>
cmp    $0xffffffff,%eax
je     147d <main+0x26d>
mov    0x18(%rsp),%r12d
mov    %r12d,%edi
call   10d0 <S_ISREG@plt>
test   %rax,%rax
je     12df <main+0xcf>
mov    0x10(%rbx),%rdi
lea    0x10(%rsp),%rsi
call   1090 <lstat@plt>
cmp    $0xffffffff,%eax
je     1390 <main+0x180>
mov    0x10(%rsp),%edi
call   1070 <S_ISDIR@plt>
test   %rax,%rax
je     13d5 <main+0x1c5>
mov    0x10(%rbx),%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
mov    0x8(%rbx),%rdi
call   1050 <strlen@plt>
lea    (%rax,%rbp,1),%rdi
add    $0x2,%rdi
call   10e0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
mov    0x8(%rbx),%rcx
mov    0x10(%rbx),%rdx
lea    0xdeb(%rip),%rsi
mov    %rbp,%rdi
call   1110 <sprintf@plt>
mov    0x8(%rbx),%rdi
mov    %rbp,%rsi
jmp    1411 <main+0x201>
mov    %r12d,%edi
call   1070 <S_ISDIR@plt>
test   %rax,%rax
je     1419 <main+0x209>
mov    0x10(%rbx),%rdi
lea    0x10(%rsp),%rsi
call   1090 <lstat@plt>
cmp    $0xffffffff,%eax
je     1430 <main+0x220>
mov    0x10(%rsp),%r15d
mov    %r15d,%edi
call   10d0 <S_ISREG@plt>
test   %rax,%rax
jne    14c9 <main+0x2b9>
mov    %r15d,%edi
call   1070 <S_ISDIR@plt>
test   %rax,%rax
je     1419 <main+0x209>
mov    0x10(%rbx),%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
mov    0x8(%rbx),%rdi
call   1050 <strlen@plt>
lea    (%rax,%rbp,1),%rdi
add    $0x2,%rdi
call   10e0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
mov    0x8(%rbx),%rcx
mov    0x10(%rbx),%rdx
lea    0xd45(%rip),%rsi
mov    %rbp,%rdi
call   1110 <sprintf@plt>
mov    %rbp,%rdi
mov    %r12d,%esi
call   1040 <mkdir@plt>
mov    0x8(%rbx),%rdi
mov    %rbp,%rsi
jmp    145a <main+0x24a>
mov    0x2c41(%rip),%rax
mov    (%rax),%rdi
mov    0x2c1f(%rip),%rax
cmp    (%rax),%rdi
je     1409 <main+0x1f9>
mov    0x2c33(%rip),%rax
mov    (%rax),%ebx
call   1130 <strerror@plt>
lea    0xc52(%rip),%rsi
lea    0xc5b(%rip),%rdx
lea    0xce7(%rip),%r8
mov    %ebx,%edi
mov    $0x64,%ecx
jmp    14b1 <main+0x2a1>
mov    0x10(%rbx),%rsi
lea    0xcdc(%rip),%rdi
call   1060 <printf@plt>
lea    0xcfb(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1100 <scanf@plt>
mov    0xf(%rsp),%al
and    $0xdf,%al
cmp    $0x59,%al
jne    1419 <main+0x209>
mov    0x10(%rbx),%rdi
call   1030 <unlink@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
mov    %r12d,%edx
call   10f0 <cp_file@plt>
mov    %r14d,%edi
call   10b0 <umask@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ba1(%rip),%rax
mov    (%rax),%rax
mov    0x2b7f(%rip),%rcx
cmp    (%rcx),%rax
jne    1419 <main+0x209>
mov    0x10(%rbx),%rdi
mov    %r12d,%esi
call   1040 <mkdir@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
call   10c0 <cp_dir@plt>
jmp    1419 <main+0x209>
mov    0x2b78(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xb8c(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    14bb <main+0x2ab>
mov    0x2b5c(%rip),%rax
mov    (%rax),%ebx
mov    0x2b4b(%rip),%rax
mov    (%rax),%rdi
call   1130 <strerror@plt>
lea    0xb71(%rip),%rsi
lea    0xb7a(%rip),%rdx
lea    0xc06(%rip),%r8
mov    %ebx,%edi
mov    $0x5b,%ecx
mov    %rax,%r9
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x2b0e(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    0x10(%rbx),%rsi
lea    0xc17(%rip),%rdi
call   1060 <printf@plt>
jmp    14bb <main+0x2ab>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [13 x i8] c"%s src dest\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.2 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day03/mycp.c\00"
@.str.3 = [6 x i8] c"lstat\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [43 x i8] c"file %s exist, do you want overwrite ? y/n\00"
@.str.6 = [4 x i8] c" %c\00"
@.str.7 = [15 x i8] c"%s is a file!\0A\00"
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 %struct.stat
%9 = alloca i8*
%10 = alloca i8
%11 = alloca i8*
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, 3
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = call i32 @umask(i32 0)
store i32 %23, i32* %6
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @lstat(i8* %26, %struct.stat* %7)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %38
29: ; preds = %22
br label %30
30: ; preds = %29
%31 = load i32, i32* @stderr
%32 = load i64, i64* @errno
%33 = call i8* @strerror(i64 %32)
%34 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0), i32 91, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; No predecessors!
br label %38
38: ; preds = %37, %22
%39 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i64 @S_ISREG(i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %138
43: ; preds = %38
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @lstat(i8* %46, %struct.stat* %8)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %73
49: ; preds = %43
%50 = load i64, i64* @errno
%51 = load i64, i64* @ENOENT
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %63
53: ; preds = %49
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load i8*, i8** %58
%60 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%61 = load i32, i32* %60
%62 = call i32 @cp_file(i8* %56, i8* %59, i32 %61)
br label %72
63: ; preds = %49
br label %64
64: ; preds = %63
%65 = load i32, i32* @stderr
%66 = load i64, i64* @errno
%67 = call i8* @strerror(i64 %66)
%68 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0), i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %67)
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; No predecessors!
br label %72
72: ; preds = %71, %53
br label %137
73: ; preds = %43
%74 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%75 = load i32, i32* %74
%76 = call i64 @S_ISDIR(i32 %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %108
78: ; preds = %73
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 2
%81 = load i8*, i8** %80
%82 = call i64 @strlen(i8* %81)
%83 = add nsw i64 %82, 1
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 1
%86 = load i8*, i8** %85
%87 = call i64 @strlen(i8* %86)
%88 = add nsw i64 %83, %87
%89 = add nsw i64 %88, 1
%90 = call i8* @malloc(i64 %89)
store i8* %90, i8** %9
%91 = load i8*, i8** %9
%92 = call i32 @memset(i8* %91, i32 0, i32 8)
%93 = load i8*, i8** %9
%94 = load i8**, i8*** %5
%95 = getelementptr inbounds i8*, i8** %94, i64 2
%96 = load i8*, i8** %95
%97 = load i8**, i8*** %5
%98 = getelementptr inbounds i8*, i8** %97, i64 1
%99 = load i8*, i8** %98
%100 = call i32 @sprintf(i8* %93, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %96, i8* %99)
%101 = load i8**, i8*** %5
%102 = getelementptr inbounds i8*, i8** %101, i64 1
%103 = load i8*, i8** %102
%104 = load i8*, i8** %9
%105 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%106 = load i32, i32* %105
%107 = call i32 @cp_file(i8* %103, i8* %104, i32 %106)
br label %136
108: ; preds = %73
%109 = load i8**, i8*** %5
%110 = getelementptr inbounds i8*, i8** %109, i64 2
%111 = load i8*, i8** %110
%112 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %111)
%113 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %10)
%114 = load i8, i8* %10
%115 = sext i8 %114 to i32
%116 = icmp eq i32 %115, 121
br i1 %116, label %121, label %117
117: ; preds = %108
%118 = load i8, i8* %10
%119 = sext i8 %118 to i32
%120 = icmp eq i32 %119, 89
br i1 %120, label %121, label %135
121: ; preds = %117, %108
%122 = load i8**, i8*** %5
%123 = getelementptr inbounds i8*, i8** %122, i64 2
%124 = load i8*, i8** %123
%125 = call i32 @unlink(i8* %124)
%126 = load i8**, i8*** %5
%127 = getelementptr inbounds i8*, i8** %126, i64 1
%128 = load i8*, i8** %127
%129 = load i8**, i8*** %5
%130 = getelementptr inbounds i8*, i8** %129, i64 2
%131 = load i8*, i8** %130
%132 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%133 = load i32, i32* %132
%134 = call i32 @cp_file(i8* %128, i8* %131, i32 %133)
br label %135
135: ; preds = %121, %117
br label %136
136: ; preds = %135, %78
br label %137
137: ; preds = %136, %72
br label %221
138: ; preds = %38
%139 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%140 = load i32, i32* %139
%141 = call i64 @S_ISDIR(i32 %140)
%142 = icmp ne i64 %141, 0
br i1 %142, label %143, label %220
143: ; preds = %138
%144 = load i8**, i8*** %5
%145 = getelementptr inbounds i8*, i8** %144, i64 2
%146 = load i8*, i8** %145
%147 = call i32 @lstat(i8* %146, %struct.stat* %8)
%148 = icmp eq i32 %147, -1
br i1 %148, label %149, label %168
149: ; preds = %143
%150 = load i64, i64* @errno
%151 = load i64, i64* @ENOENT
%152 = icmp eq i64 %150, %151
br i1 %152, label %153, label %167
153: ; preds = %149
%154 = load i8**, i8*** %5
%155 = getelementptr inbounds i8*, i8** %154, i64 2
%156 = load i8*, i8** %155
%157 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%158 = load i32, i32* %157
%159 = call i32 @mkdir(i8* %156, i32 %158)
%160 = load i8**, i8*** %5
%161 = getelementptr inbounds i8*, i8** %160, i64 1
%162 = load i8*, i8** %161
%163 = load i8**, i8*** %5
%164 = getelementptr inbounds i8*, i8** %163, i64 2
%165 = load i8*, i8** %164
%166 = call i32 @cp_dir(i8* %162, i8* %165)
br label %167
167: ; preds = %153, %149
br label %219
168: ; preds = %143
%169 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%170 = load i32, i32* %169
%171 = call i64 @S_ISREG(i32 %170)
%172 = icmp ne i64 %171, 0
br i1 %172, label %173, label %180
173: ; preds = %168
%174 = load i8**, i8*** %5
%175 = getelementptr inbounds i8*, i8** %174, i64 2
%176 = load i8*, i8** %175
%177 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %176)
%178 = load i32, i32* @EXIT_FAILURE
%179 = call i32 @exit(i32 %178)
unreachable
180: ; preds = %168
%181 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%182 = load i32, i32* %181
%183 = call i64 @S_ISDIR(i32 %182)
%184 = icmp ne i64 %183, 0
br i1 %184, label %185, label %217
185: ; preds = %180
%186 = load i8**, i8*** %5
%187 = getelementptr inbounds i8*, i8** %186, i64 2
%188 = load i8*, i8** %187
%189 = call i64 @strlen(i8* %188)
%190 = add nsw i64 %189, 1
%191 = load i8**, i8*** %5
%192 = getelementptr inbounds i8*, i8** %191, i64 1
%193 = load i8*, i8** %192
%194 = call i64 @strlen(i8* %193)
%195 = add nsw i64 %190, %194
%196 = add nsw i64 %195, 1
%197 = call i8* @malloc(i64 %196)
store i8* %197, i8** %11
%198 = load i8*, i8** %11
%199 = call i32 @memset(i8* %198, i32 0, i32 8)
%200 = load i8*, i8** %11
%201 = load i8**, i8*** %5
%202 = getelementptr inbounds i8*, i8** %201, i64 2
%203 = load i8*, i8** %202
%204 = load i8**, i8*** %5
%205 = getelementptr inbounds i8*, i8** %204, i64 1
%206 = load i8*, i8** %205
%207 = call i32 @sprintf(i8* %200, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %203, i8* %206)
%208 = load i8*, i8** %11
%209 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%210 = load i32, i32* %209
%211 = call i32 @mkdir(i8* %208, i32 %210)
%212 = load i8**, i8*** %5
%213 = getelementptr inbounds i8*, i8** %212, i64 1
%214 = load i8*, i8** %213
%215 = load i8*, i8** %11
%216 = call i32 @cp_dir(i8* %214, i8* %215)
br label %217
217: ; preds = %185, %180
br label %218
218: ; preds = %217
br label %219
219: ; preds = %218, %167
br label %220
220: ; preds = %219, %138
br label %221
221: ; preds = %220, %137
%222 = load i32, i32* %6
%223 = call i32 @umask(i32 %222)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [13 x i8] c"%s src dest\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.2 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day03/mycp.c\00"
@.str.3 = [6 x i8] c"lstat\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [43 x i8] c"file %s exist, do you want overwrite ? y/n\00"
@.str.6 = [4 x i8] c" %c\00"
@.str.7 = [15 x i8] c"%s is a file!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = alloca i8
%6 = icmp eq i32 %0, 3
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = tail call i32 @umask(i32 0)
%15 = bitcast %struct.stat* %3 to i8*
%16 = bitcast %struct.stat* %4 to i8*
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @lstat(i8* %18, %struct.stat* %3)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %28
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = load i64, i64* @errno
%24 = tail call i8* @strerror(i64 %23)
%25 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0), i32 91, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %13
%29 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%30 = load i32, i32* %29
%31 = tail call i64 @S_ISREG(i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %85, label %33
33: ; preds = %28
%34 = getelementptr inbounds i8*, i8** %1, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @lstat(i8* %35, %struct.stat* %4)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %52
38: ; preds = %33
%39 = load i64, i64* @errno
%40 = load i64, i64* @ENOENT
%41 = icmp eq i64 %39, %40
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load i8*, i8** %17
%44 = load i8*, i8** %34
%45 = tail call i32 @cp_file(i8* %43, i8* %44, i32 %30)
br label %131
46: ; preds = %38
%47 = load i32, i32* @stderr
%48 = tail call i8* @strerror(i64 %39)
%49 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0), i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %48)
%50 = load i32, i32* @EXIT_FAILURE
%51 = tail call i32 @exit(i32 %50)
unreachable
52: ; preds = %33
%53 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%54 = load i32, i32* %53
%55 = tail call i64 @S_ISDIR(i32 %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %71, label %57
57: ; preds = %52
%58 = load i8*, i8** %34
%59 = tail call i64 @strlen(i8* dereferenceable(1) %58)
%60 = load i8*, i8** %17
%61 = tail call i64 @strlen(i8* dereferenceable(1) %60)
%62 = add i64 %59, 2
%63 = add i64 %62, %61
%64 = tail call i8* @malloc(i64 %63)
%65 = tail call i32 @memset(i8* %64, i32 0, i32 8)
%66 = load i8*, i8** %34
%67 = load i8*, i8** %17
%68 = tail call i32 @sprintf(i8* dereferenceable(1) %64, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %66, i8* %67)
%69 = load i8*, i8** %17
%70 = tail call i32 @cp_file(i8* %69, i8* %64, i32 %30)
br label %131
71: ; preds = %52
%72 = load i8*, i8** %34
%73 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %72)
%74 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%75 = load i8, i8* %5
%76 = and i8 %75, -33
%77 = icmp eq i8 %76, 89
br i1 %77, label %78, label %84
78: ; preds = %71
%79 = load i8*, i8** %34
%80 = call i32 @unlink(i8* %79)
%81 = load i8*, i8** %17
%82 = load i8*, i8** %34
%83 = call i32 @cp_file(i8* %81, i8* %82, i32 %30)
br label %84
84: ; preds = %71, %78
br label %131
85: ; preds = %28
%86 = tail call i64 @S_ISDIR(i32 %30)
%87 = icmp eq i64 %86, 0
br i1 %87, label %131, label %88
88: ; preds = %85
%89 = getelementptr inbounds i8*, i8** %1, i64 2
%90 = load i8*, i8** %89
%91 = call i32 @lstat(i8* %90, %struct.stat* %4)
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %103
93: ; preds = %88
%94 = load i64, i64* @errno
%95 = load i64, i64* @ENOENT
%96 = icmp eq i64 %94, %95
br i1 %96, label %97, label %131
97: ; preds = %93
%98 = load i8*, i8** %89
%99 = tail call i32 @mkdir(i8* %98, i32 %30)
%100 = load i8*, i8** %17
%101 = load i8*, i8** %89
%102 = tail call i32 @cp_dir(i8* %100, i8* %101)
br label %131
103: ; preds = %88
%104 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%105 = load i32, i32* %104
%106 = tail call i64 @S_ISREG(i32 %105)
%107 = icmp eq i64 %106, 0
br i1 %107, label %113, label %108
108: ; preds = %103
%109 = load i8*, i8** %89
%110 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %109)
%111 = load i32, i32* @EXIT_FAILURE
%112 = tail call i32 @exit(i32 %111)
unreachable
113: ; preds = %103
%114 = tail call i64 @S_ISDIR(i32 %105)
%115 = icmp eq i64 %114, 0
br i1 %115, label %131, label %116
116: ; preds = %113
%117 = load i8*, i8** %89
%118 = tail call i64 @strlen(i8* dereferenceable(1) %117)
%119 = load i8*, i8** %17
%120 = tail call i64 @strlen(i8* dereferenceable(1) %119)
%121 = add i64 %118, 2
%122 = add i64 %121, %120
%123 = tail call i8* @malloc(i64 %122)
%124 = tail call i32 @memset(i8* %123, i32 0, i32 8)
%125 = load i8*, i8** %89
%126 = load i8*, i8** %17
%127 = tail call i32 @sprintf(i8* dereferenceable(1) %123, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %125, i8* %126)
%128 = tail call i32 @mkdir(i8* %123, i32 %30)
%129 = load i8*, i8** %17
%130 = tail call i32 @cp_dir(i8* %129, i8* %123)
br label %131
131: ; preds = %85, %116, %113, %93, %97, %42, %84, %57
%132 = call i32 @umask(i32 %14)
ret i32 0
}