#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 {
  scalar_t__ st_blksize;
};

/* Variables and functions */
char *dirname(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ stat(char const *, struct stat *);
char *strdup(char const *);
int getBlockSize(const char *path) {
  struct stat fi;
  int size;
  if (stat(path, &fi) < 0) {
    char *newPath = strdup(path);
    char *dirName = dirname(newPath);
    if (stat(dirName, &fi) < 0) {
      free(newPath);
      return 4096;
    }
    free(newPath);
    dirName = NULL;
  }
  size = (int)fi.st_blksize;
  return (size > 0 ? size : 4096);
}


x86 assembly (clang, -O0):
<getBlockSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    11ba <getBlockSize+0x7a>
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <dirname@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    11a9 <getBlockSize+0x69>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1000,-0x4(%rbp)
jmp    11e9 <getBlockSize+0xa9>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11d6 <getBlockSize+0x96>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    11e3 <getBlockSize+0xa3>
mov    $0x1000,%eax
mov    %eax,-0x34(%rbp)
jmp    11e3 <getBlockSize+0xa3>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getBlockSize>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1050 <stat@plt>
test   %rax,%rax
jns    1182 <getBlockSize+0x42>
mov    %rbx,%rdi
call   1060 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <dirname@plt>
mov    %rsp,%rsi
mov    %rax,%rdi
call   1050 <stat@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14,%r14
js     1197 <getBlockSize+0x57>
mov    (%rsp),%ecx
test   %ecx,%ecx
mov    $0x1000,%eax
cmovg  %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1000,%eax
jmp    118f <getBlockSize+0x4f>

LLVM IR (-O0):
%struct.stat = type { i64 }
define i32 @getBlockSize(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @stat(i8* %8, %struct.stat* %4)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i8* @strdup(i8* %12)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = call i8* @dirname(i8* %14)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = call i64 @stat(i8* %16, %struct.stat* %4)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = load i8*, i8** %6
%21 = call i32 @free(i8* %20)
store i32 4096, i32* %2
br label %36
22: ; preds = %11
%23 = load i8*, i8** %6
%24 = call i32 @free(i8* %23)
store i8* null, i8** %7
br label %25
25: ; preds = %22, %1
%26 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%27 = load i64, i64* %26
%28 = trunc i64 %27 to i32
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = load i32, i32* %5
br label %34
33: ; preds = %25
br label %34
34: ; preds = %33, %31
%35 = phi i32 [ %32, %31 ], [ 4096, %33 ]
store i32 %35, i32* %2
br label %36
36: ; preds = %34, %19
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
%struct.stat = type { i64 }
define i32 @getBlockSize(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* %0, %struct.stat* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %1
%7 = call i8* @strdup(i8* %0)
%8 = call i8* @dirname(i8* %7)
%9 = call i64 @stat(i8* %8, %struct.stat* %2)
%10 = icmp slt i64 %9, 0
%11 = call i32 @free(i8* %7)
br i1 %10, label %18, label %12
12: ; preds = %6, %1
%13 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%14 = load i64, i64* %13
%15 = trunc i64 %14 to i32
%16 = icmp sgt i32 %15, 0
%17 = select i1 %16, i32 %15, i32 4096
br label %18
18: ; preds = %6, %12
%19 = phi i32 [ %17, %12 ], [ 4096, %6 ]
ret i32 %19
}