#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 */
char *dirname(char *);
int /*<<< orphan*/ printf(char *, char *, char *, char *, char *);
char *strdup(char *);
int main() {
  char *pList[][3] = {{"/usr/lib", "/usr", "lib"},
                      {"/usr/", "/", "usr"},
                      {"usr", ".", "usr"},
                      {"/", "/", "/"},
                      {".", ".", "."},
                      {"..", ".", ".."},
                      {NULL, NULL, NULL}};
  int i = 0;
  for (i = 0; pList[i][0] != NULL; i++) {
    char *p = strdup(pList[i][0]);
    char *dir = dirname(p);
    printf("src : [%s], \texp : [%s], \tdir : [%s], \tp : [%s]\n", pList[i][0],
           pList[i][1], dir, p);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xb0(%rbp),%rdi
lea    0x2c10(%rip),%rsi
mov    $0xa8,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0xb4(%rbp)
movl   $0x0,-0xb4(%rbp)
movslq -0xb4(%rbp),%rcx
lea    -0xb0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
cmpq   $0x0,(%rax)
je     1233 <main+0xf3>
movslq -0xb4(%rbp),%rcx
lea    -0xb0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%rdi
call   1060 <strdup@plt>
mov    %rax,-0xc0(%rbp)
mov    -0xc0(%rbp),%rdi
call   1040 <dirname@plt>
mov    %rax,-0xc8(%rbp)
movslq -0xb4(%rbp),%rcx
lea    -0xb0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%rsi
movslq -0xb4(%rbp),%rcx
lea    -0xb0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rdx
mov    -0xc8(%rbp),%rcx
mov    -0xc0(%rbp),%r8
lea    0xdfd(%rip),%rdi
call   1030 <printf@plt>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    117e <main+0x3e>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xec0(%rip),%r15
mov    %r15,%rdi
call   1050 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <dirname@plt>
lea    0xebd(%rip),%r14
lea    0xea8(%rip),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rcx
mov    %rbx,%r8
call   1030 <printf@plt>
lea    0xe95(%rip),%r15
mov    %r15,%rdi
call   1050 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <dirname@plt>
lea    0xe7f(%rip),%r12
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rax,%rcx
mov    %rbx,%r8
call   1030 <printf@plt>
lea    0xe5c(%rip),%r13
mov    %r13,%rdi
call   1050 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <dirname@plt>
lea    0xe4d(%rip),%r15
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    %rax,%rcx
mov    %rbx,%r8
call   1030 <printf@plt>
mov    %r12,%rdi
call   1050 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <dirname@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r12,%rdx
mov    %rax,%rcx
mov    %rbx,%r8
call   1030 <printf@plt>
mov    %r15,%rdi
call   1050 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <dirname@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r15,%rdx
mov    %rax,%rcx
mov    %rbx,%r8
call   1030 <printf@plt>
lea    0xde3(%rip),%r12
mov    %r12,%rdi
call   1050 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <dirname@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %rax,%rcx
mov    %rbx,%r8
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"/usr/lib\00"
@.str.1 = [5 x i8] c"/usr\00"
@.str.2 = [4 x i8] c"lib\00"
@.str.3 = [6 x i8] c"/usr/\00"
@.str.4 = [2 x i8] c"/\00"
@.str.5 = [4 x i8] c"usr\00"
@.str.6 = [2 x i8] c".\00"
@.str.7 = [3 x i8] c"..\00"
@__const.main.pList = [7 x [3 x i8*]] [[3 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i32 0, i32 0)], [3 x i8*] zeroinitializer]
@.str.8 = [49 x i8] c"src : [%s], \09exp : [%s], \09dir : [%s], \09p : [%s]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [7 x [3 x i8*]]
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
%6 = bitcast [7 x [3 x i8*]]* %2 to i8*
store i32 0, i32* %3
store i32 0, i32* %3
br label %7
7: ; preds = %36, %0
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [7 x [3 x i8*]], [7 x [3 x i8*]]* %2, i64 0, i64 %9
%11 = getelementptr inbounds [3 x i8*], [3 x i8*]* %10, i64 0, i64 0
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %39
14: ; preds = %7
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [7 x [3 x i8*]], [7 x [3 x i8*]]* %2, i64 0, i64 %16
%18 = getelementptr inbounds [3 x i8*], [3 x i8*]* %17, i64 0, i64 0
%19 = load i8*, i8** %18
%20 = call i8* @strdup(i8* %19)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = call i8* @dirname(i8* %21)
store i8* %22, i8** %5
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [7 x [3 x i8*]], [7 x [3 x i8*]]* %2, i64 0, i64 %24
%26 = getelementptr inbounds [3 x i8*], [3 x i8*]* %25, i64 0, i64 0
%27 = load i8*, i8** %26
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [7 x [3 x i8*]], [7 x [3 x i8*]]* %2, i64 0, i64 %29
%31 = getelementptr inbounds [3 x i8*], [3 x i8*]* %30, i64 0, i64 1
%32 = load i8*, i8** %31
%33 = load i8*, i8** %5
%34 = load i8*, i8** %4
%35 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0), i8* %27, i8* %32, i8* %33, i8* %34)
br label %36
36: ; preds = %14
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %7
39: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"/usr/lib\00"
@.str.1 = [5 x i8] c"/usr\00"
@.str.3 = [6 x i8] c"/usr/\00"
@.str.4 = [2 x i8] c"/\00"
@.str.5 = [4 x i8] c"usr\00"
@.str.6 = [2 x i8] c".\00"
@.str.7 = [3 x i8] c"..\00"
@.str.8 = [49 x i8] c"src : [%s], \09exp : [%s], \09dir : [%s], \09p : [%s]\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(9) i8* @strdup(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%2 = tail call i8* @dirname(i8* %1)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %1)
%4 = tail call dereferenceable_or_null(6) i8* @strdup(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%5 = tail call i8* @dirname(i8* %4)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* %5, i8* %4)
%7 = tail call dereferenceable_or_null(4) i8* @strdup(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%8 = tail call i8* @dirname(i8* %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %8, i8* %7)
%10 = tail call dereferenceable_or_null(2) i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%11 = tail call i8* @dirname(i8* %10)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* %11, i8* %10)
%13 = tail call dereferenceable_or_null(2) i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%14 = tail call i8* @dirname(i8* %13)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %14, i8* %13)
%16 = tail call dereferenceable_or_null(3) i8* @strdup(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%17 = tail call i8* @dirname(i8* %16)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %17, i8* %16)
ret i32 0
}