#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*/ strcpy(char *, char *);
int strlen(char *);
void getdirname(char *in, char *out) {
  int len = strlen(in);
  char *p;
  int found_it = 0;
  strcpy(out, in);
  for (p = &out[len - 1]; p > out; p--) {
    if (*p == '/') {
      p[1] = 0;
      found_it = 1;
      break;
    }
  }
  if (!found_it)
    out[0] = 0;
}


x86 assembly (clang, -O0):
<getdirname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    11ac <getdirname+0x8c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1196 <getdirname+0x76>
mov    -0x20(%rbp),%rax
movb   $0x0,0x1(%rax)
movl   $0x1,-0x24(%rbp)
jmp    11ac <getdirname+0x8c>
jmp    119b <getdirname+0x7b>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1164 <getdirname+0x44>
cmpl   $0x0,-0x24(%rbp)
jne    11bd <getdirname+0x9d>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getdirname>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
cmp    $0x2,%ebx
jl     1167 <getdirname+0x47>
add    $0xffffffff,%ebx
add    %r14,%rbx
nopl   0x0(%rax,%rax,1)
cmpb   $0x2f,(%rbx)
je     1160 <getdirname+0x40>
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
ja     1150 <getdirname+0x30>
jmp    1167 <getdirname+0x47>
add    $0x1,%rbx
mov    %rbx,%r14
movb   $0x0,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @getdirname(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %5
store i32 0, i32* %7
%10 = load i8*, i8** %4
%11 = load i8*, i8** %3
%12 = call i32 @strcpy(i8* %10, i8* %11)
%13 = load i8*, i8** %4
%14 = load i32, i32* %5
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
store i8* %17, i8** %6
br label %18
18: ; preds = %31, %2
%19 = load i8*, i8** %6
%20 = load i8*, i8** %4
%21 = icmp ugt i8* %19, %20
br i1 %21, label %22, label %34
22: ; preds = %18
%23 = load i8*, i8** %6
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 47
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i8*, i8** %6
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8 0, i8* %29
store i32 1, i32* %7
br label %34
30: ; preds = %22
br label %31
31: ; preds = %30
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i32 -1
store i8* %33, i8** %6
br label %18
34: ; preds = %27, %18
%35 = load i32, i32* %7
%36 = icmp ne i32 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %34
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i64 0
store i8 0, i8* %39
br label %40
40: ; preds = %37, %34
ret void
}

LLVM IR (-O2):
define void @getdirname(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strcpy(i8* %1, i8* %0)
%5 = icmp sgt i32 %3, 1
br i1 %5, label %6, label %19
6: ; preds = %2
%7 = add nsw i32 %3, -1
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %1, i64 %8
br label %10
10: ; preds = %6, %16
%11 = phi i8* [ %17, %16 ], [ %9, %6 ]
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %11, i64 1
br label %19
16: ; preds = %10
%17 = getelementptr inbounds i8, i8* %11, i64 -1
%18 = icmp ugt i8* %17, %1
br i1 %18, label %10, label %19
19: ; preds = %16, %2, %14
%20 = phi i8* [ %15, %14 ], [ %1, %2 ], [ %1, %16 ]
store i8 0, i8* %20
ret void
}