#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 MAXPATHLEN;
int path_canonicalizer(char *);
int path_split(char *, char **, char **);
int /*<<< orphan*/ printf(char *, int, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char **argv) {
  char path[MAXPATHLEN], *dirname, *basename;
  int i;
  if (argc > 1) {
    strncpy(path, argv[1], MAXPATHLEN);
  } else {
    strcpy(path, "/foo/bar");
  }
  i = path_canonicalizer(path);
  printf("i: %i, path: %s\n", i, path);
  i = path_split(path, &dirname, &basename);
  printf("relative: %i, dirname: %s, basename: %s\n", i, dirname, basename);
  return 0;
}


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)
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11bb <main+0x6b>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
jmp    11cb <main+0x7b>
mov    -0x40(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x40(%rbp),%rdi
call   1070 <path_canonicalizer@plt>
mov    -0x40(%rbp),%rdx
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <path_split@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x2,%edi
jl     1186 <main+0x36>
mov    0x8(%rsi),%rsi
mov    %rbx,%rdi
call   1030 <strncpy@plt>
jmp    1195 <main+0x45>
lea    0xe73(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1070 <path_canonicalizer@plt>
lea    0xe65(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    -0x18(%rbp),%rsi
lea    -0x10(%rbp),%rdx
mov    %rbx,%rdi
call   1060 <path_split@plt>
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe4b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@.str = [9 x i8] c"/foo/bar\00"
@.str.1 = [17 x i8] c"i: %i, path: %s\0A\00"
@.str.2 = [41 x i8] c"relative: %i, dirname: %s, basename: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @MAXPATHLEN
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i8, i64 %12
store i64 %12, i64* %7
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @MAXPATHLEN
%22 = call i32 @strncpy(i8* %14, i8* %20, i32 %21)
br label %25
23: ; preds = %2
%24 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %17
%26 = call i32 @path_canonicalizer(i8* %14)
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %27, i8* %14)
%29 = call i32 @path_split(i8* %14, i8** %8, i8** %9)
store i32 %29, i32* %10
%30 = load i32, i32* %10
%31 = load i8*, i8** %8
%32 = load i8*, i8** %9
%33 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %30, i8* %31, i8* %32)
store i32 0, i32* %3
%34 = load i8*, i8** %6
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@.str = [9 x i8] c"/foo/bar\00"
@.str.1 = [17 x i8] c"i: %i, path: %s\0A\00"
@.str.2 = [41 x i8] c"relative: %i, dirname: %s, basename: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = load i32, i32* @MAXPATHLEN
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = bitcast i8** %3 to i8*
%9 = bitcast i8** %4 to i8*
%10 = icmp sgt i32 %0, 1
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @strncpy(i8* %7, i8* %13, i32 %5)
br label %17
15: ; preds = %2
%16 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = call i32 @path_canonicalizer(i8* %7)
%19 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %18, i8* %7)
%20 = call i32 @path_split(i8* %7, i8** %3, i8** %4)
%21 = load i8*, i8** %3
%22 = load i8*, i8** %4
%23 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %20, i8* %21, i8* %22)
ret i32 0
}