#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 */

/* Variables and functions */
int /*<<< orphan*/ GetFilPathForLot(char *, int, char *);
int atol(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char getopt(int, char **, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recursiveDir(char *, char *, int, char *, char *);
int /*<<< orphan*/ rmkdir(char *, int, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
main(int argc, char *argv[]) {
  char lotpath[512];
  int lotNr;
  char file[512];
  char *optHost = NULL;
  extern char *optarg;
  extern int optind, opterr, optopt;
  char c;
  while ((c = getopt(argc, argv, "h:")) != -1) {
    switch (c) {
    case 'h':
      optHost = optarg;
      fprintf(stderr, "Will send to host %s\n", optHost);
      break;
    default:
      exit(1);
    }
  }
  --optind;
  if (argc - optind < 3) {
    printf("Dette programet kopierer en lot til en annen server\n\n\t./lotcp "
           "lotnr subname [file]\n\n");
    printf("Options:\n\t-h host\n\n");
    exit(0);
  }
  lotNr = atol(argv[1 + optind]);
  char *subname = argv[2 + optind];
  rmkdir("", lotNr, subname);
  GetFilPathForLot(lotpath, lotNr, argv[2 + optind]);
  if ((argc - optind) == 3) {
    recursiveDir(lotpath, "", lotNr, subname, optHost);
  } else if ((argc - optind) == 4) {
    strcpy(file, argv[3 + optind]);
    if ((strchr(file, '/') != NULL) && (file[strlen(file) - 1] != '/')) {
      printf("adding a / to \"%s\"\n", file);
      strcat(file, "/");
    }
    recursiveDir(lotpath, file, lotNr, subname, optHost);
  } else {
    fprintf(stderr, "wrong argc count.\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x428(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe0e(%rip),%rdx
call   10c0 <getopt@plt>
mov    %al,-0x429(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     125f <main+0x9f>
mov    -0x429(%rbp),%al
sub    $0x68,%al
jne    1250 <main+0x90>
jmp    121c <main+0x5c>
mov    0x2dbd(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x428(%rbp)
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
mov    -0x428(%rbp),%rdx
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    125a <main+0x9a>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    11e4 <main+0x24>
mov    0x2d6a(%rip),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    0x2d5e(%rip),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%eax
mov    0x2d52(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x3,%eax
jge    12ac <main+0xec>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x2d19(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   10b0 <atol@plt>
mov    %eax,-0x214(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2cf7(%rip),%rcx
mov    (%rcx),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x438(%rbp)
mov    -0x214(%rbp),%esi
mov    -0x438(%rbp),%rdx
lea    0xd6d(%rip),%rdi
call   1080 <rmkdir@plt>
lea    -0x210(%rbp),%rdi
mov    -0x214(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x2cb3(%rip),%rcx
mov    (%rcx),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
call   1090 <GetFilPathForLot@plt>
mov    -0x8(%rbp),%eax
mov    0x2c98(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x3,%eax
jne    136f <main+0x1af>
lea    -0x210(%rbp),%rdi
mov    -0x214(%rbp),%edx
mov    -0x438(%rbp),%rcx
mov    -0x428(%rbp),%r8
lea    0xd08(%rip),%rsi
call   1030 <recursiveDir@plt>
jmp    1454 <main+0x294>
mov    -0x8(%rbp),%eax
mov    0x2c57(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x4,%eax
jne    1438 <main+0x278>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x2c3a(%rip),%rcx
mov    (%rcx),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
lea    -0x420(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
je     140c <main+0x24c>
lea    -0x420(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
je     140c <main+0x24c>
lea    -0x420(%rbp),%rsi
lea    0xc90(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x420(%rbp),%rdi
lea    0xc8f(%rip),%rsi
call   10d0 <strcat@plt>
lea    -0x210(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    -0x214(%rbp),%edx
mov    -0x438(%rbp),%rcx
mov    -0x428(%rbp),%r8
call   1030 <recursiveDir@plt>
jmp    144f <main+0x28f>
mov    0x2b99(%rip),%rax
mov    (%rax),%edi
lea    0xc50(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1454 <main+0x294>
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r12
mov    %edi,%ebp
lea    0xe13(%rip),%r14
mov    0x2dec(%rip),%r13
lea    0xe08(%rip),%r15
xor    %ebx,%ebx
nopl   (%rax)
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   10d0 <getopt@plt>
cmp    $0x68,%al
jne    122d <main+0x5d>
mov    0x0(%r13),%rbx
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    1200 <main+0x30>
cmp    $0xff,%al
jne    134d <main+0x17d>
mov    0x2d94(%rip),%r14
movslq (%r14),%r13
lea    -0x1(%r13),%eax
mov    %eax,(%r14)
mov    %ebp,%ecx
sub    %eax,%ecx
cmp    $0x2,%ecx
jle    1357 <main+0x187>
mov    (%r12,%r13,8),%rdi
call   10c0 <atol@plt>
mov    %eax,%r15d
mov    0x8(%r12,%r13,8),%r13
lea    0xdc1(%rip),%rdi
mov    %eax,%esi
mov    %r13,%rdx
call   1090 <rmkdir@plt>
movslq (%r14),%rax
mov    0x10(%r12,%rax,8),%rdx
lea    0x200(%rsp),%rdi
mov    %r15d,%esi
call   10a0 <GetFilPathForLot@plt>
movslq (%r14),%rax
sub    %eax,%ebp
cmp    $0x4,%ebp
je     12b1 <main+0xe1>
cmp    $0x3,%ebp
jne    1322 <main+0x152>
lea    0xd85(%rip),%rsi
lea    0x200(%rsp),%rdi
jmp    1312 <main+0x142>
mov    0x18(%r12,%rax,8),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     1307 <main+0x137>
mov    %rbp,%rdi
call   1060 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbp,1)
je     1307 <main+0x137>
lea    0xd2e(%rip),%rdi
mov    %rsp,%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd2e(%rip),%rsi
mov    %rbp,%rdi
call   10e0 <strcat@plt>
lea    0x200(%rsp),%rdi
mov    %rsp,%rsi
mov    %r15d,%edx
mov    %r13,%rcx
mov    %rbx,%r8
call   1030 <recursiveDir@plt>
jmp    1339 <main+0x169>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
lea    0xcfd(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xce4(%rip),%rdi
call   1050 <puts@plt>
lea    0xd2c(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"h:\00"
@optarg = external global i8*
@stderr = global i32 0
@.str.1 = [22 x i8] c"Will send to host %s\0A\00"
@optind = external global i32
@.str.2 = [85 x i8] c"Dette programet kopierer en lot til en annen server\0A\0A\09./lotcp lotnr subname [file]\0A\0A\00"
@.str.3 = [20 x i8] c"Options:\0A\09-h host\0A\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [20 x i8] c"adding a / to \22%s\22\0A\00"
@.str.6 = [2 x i8] c"/\00"
@.str.7 = [19 x i8] c"wrong argc count.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca i32
%8 = alloca [512 x i8]
%9 = alloca i8*
%10 = alloca i8
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %9
br label %12
12: ; preds = %28, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call signext i8 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8 %15, i8* %10
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %29
18: ; preds = %12
%19 = load i8, i8* %10
%20 = sext i8 %19 to i32
switch i32 %20, label %26 [
i32 104, label %21
]
21: ; preds = %18
%22 = load i8*, i8** @optarg
store i8* %22, i8** %9
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %9
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %28
26: ; preds = %18
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %21
br label %12
29: ; preds = %12
%30 = load i32, i32* @optind
%31 = add nsw i32 %30, -1
store i32 %31, i32* @optind
%32 = load i32, i32* %4
%33 = load i32, i32* @optind
%34 = sub nsw i32 %32, %33
%35 = icmp slt i32 %34, 3
br i1 %35, label %36, label %40
36: ; preds = %29
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 @exit(i32 0)
unreachable
40: ; preds = %29
%41 = load i8**, i8*** %5
%42 = load i32, i32* @optind
%43 = add nsw i32 1, %42
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %41, i64 %44
%46 = load i8*, i8** %45
%47 = call i32 @atol(i8* %46)
store i32 %47, i32* %7
%48 = load i8**, i8*** %5
%49 = load i32, i32* @optind
%50 = add nsw i32 2, %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %48, i64 %51
%53 = load i8*, i8** %52
store i8* %53, i8** %11
%54 = load i32, i32* %7
%55 = load i8*, i8** %11
%56 = call i32 @rmkdir(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 %54, i8* %55)
%57 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%58 = load i32, i32* %7
%59 = load i8**, i8*** %5
%60 = load i32, i32* @optind
%61 = add nsw i32 2, %60
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %59, i64 %62
%64 = load i8*, i8** %63
%65 = call i32 @GetFilPathForLot(i8* %57, i32 %58, i8* %64)
%66 = load i32, i32* %4
%67 = load i32, i32* @optind
%68 = sub nsw i32 %66, %67
%69 = icmp eq i32 %68, 3
br i1 %69, label %70, label %76
70: ; preds = %40
%71 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%72 = load i32, i32* %7
%73 = load i8*, i8** %11
%74 = load i8*, i8** %9
%75 = call i32 @recursiveDir(i8* %71, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 %72, i8* %73, i8* %74)
br label %118
76: ; preds = %40
%77 = load i32, i32* %4
%78 = load i32, i32* @optind
%79 = sub nsw i32 %77, %78
%80 = icmp eq i32 %79, 4
br i1 %80, label %81, label %114
81: ; preds = %76
%82 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%83 = load i8**, i8*** %5
%84 = load i32, i32* @optind
%85 = add nsw i32 3, %84
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8*, i8** %83, i64 %86
%88 = load i8*, i8** %87
%89 = call i32 @strcpy(i8* %82, i8* %88)
%90 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%91 = call i32* @strchr(i8* %90, i8 signext 47)
%92 = icmp ne i32* %91, null
br i1 %92, label %93, label %107
93: ; preds = %81
%94 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%95 = call i32 @strlen(i8* %94)
%96 = sub nsw i32 %95, 1
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 %97
%99 = load i8, i8* %98
%100 = sext i8 %99 to i32
%101 = icmp ne i32 %100, 47
br i1 %101, label %102, label %107
102: ; preds = %93
%103 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %103)
%105 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%106 = call i32 @strcat(i8* %105, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %107
107: ; preds = %102, %93, %81
%108 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%109 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%110 = load i32, i32* %7
%111 = load i8*, i8** %11
%112 = load i8*, i8** %9
%113 = call i32 @recursiveDir(i8* %108, i8* %109, i32 %110, i8* %111, i8* %112)
br label %117
114: ; preds = %76
%115 = load i32, i32* @stderr
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %117
117: ; preds = %114, %107
br label %118
118: ; preds = %117, %70
%119 = load i32, i32* %3
ret i32 %119
}

LLVM IR (-O2):
@.str = [3 x i8] c"h:\00"
@optarg = external global i8*
@stderr = global i32 0
@.str.1 = [22 x i8] c"Will send to host %s\0A\00"
@optind = external global i32
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [20 x i8] c"adding a / to \22%s\22\0A\00"
@.str.6 = [2 x i8] c"/\00"
@.str.7 = [19 x i8] c"wrong argc count.\0A\00"
@str = [84 x i8] c"Dette programet kopierer en lot til en annen server\0A\0A\09./lotcp lotnr subname [file]\0A\00"
@str.8 = [19 x i8] c"Options:\0A\09-h host\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [512 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
br label %7
7: ; preds = %10, %2
%8 = phi i8* [ null, %2 ], [ %11, %10 ]
%9 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i8 %9, label %14 [
i8 -1, label %16
i8 104, label %10
]
10: ; preds = %7
%11 = load i8*, i8** @optarg
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %7
14: ; preds = %7
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %7
%17 = load i32, i32* @optind
%18 = add nsw i32 %17, -1
store i32 %18, i32* @optind
%19 = sub nsw i32 %0, %18
%20 = icmp slt i32 %19, 3
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([84 x i8], [84 x i8]* @str, i64 0, i64 0))
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.8, i64 0, i64 0))
%24 = tail call i32 @exit(i32 0)
unreachable
25: ; preds = %16
%26 = sext i32 %17 to i64
%27 = getelementptr inbounds i8*, i8** %1, i64 %26
%28 = load i8*, i8** %27
%29 = tail call i32 @atol(i8* %28)
%30 = add nsw i32 %17, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %1, i64 %31
%33 = load i8*, i8** %32
%34 = tail call i32 @rmkdir(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 %29, i8* %33)
%35 = load i32, i32* @optind
%36 = add nsw i32 %35, 2
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %1, i64 %37
%39 = load i8*, i8** %38
%40 = call i32 @GetFilPathForLot(i8* %5, i32 %29, i8* %39)
%41 = load i32, i32* @optind
%42 = sub nsw i32 %0, %41
switch i32 %42, label %65 [
i32 3, label %43
i32 4, label %45
]
43: ; preds = %25
%44 = call i32 @recursiveDir(i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 %29, i8* %33, i8* %8)
br label %68
45: ; preds = %25
%46 = add nsw i32 %41, 3
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %1, i64 %47
%49 = load i8*, i8** %48
%50 = call i32 @strcpy(i8* %6, i8* %49)
%51 = call i32* @strchr(i8* %6, i8 signext 47)
%52 = icmp eq i32* %51, null
br i1 %52, label %63, label %53
53: ; preds = %45
%54 = call i32 @strlen(i8* %6)
%55 = add nsw i32 %54, -1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %56
%58 = load i8, i8* %57
%59 = icmp eq i8 %58, 47
br i1 %59, label %63, label %60
60: ; preds = %53
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%62 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %63
63: ; preds = %60, %53, %45
%64 = call i32 @recursiveDir(i8* %5, i8* %6, i32 %29, i8* %33, i8* %8)
br label %68
65: ; preds = %25
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %68
68: ; preds = %63, %65, %43
ret i32 0
}