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

/* Variables and functions */
int stat(char *, struct stat *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strrchr(char *, char);
_get_sector_size(char *name) {
  int status;
  struct stat check_stat;
  int nbytes;
  char local_name[256];
  char *last_slash;
  strcpy(local_name, name);
  last_slash = strrchr(local_name, '/');
  if (last_slash == NULL) {
    strcpy(local_name, ".");
  } else {
    last_slash[0] = '\0';
  }
  status = stat(local_name, &check_stat);
  if (status == -1) {
    return (1);
  }
  nbytes = check_stat.st_blksize;
  if (nbytes == 0)
    nbytes = 4096;
  return (nbytes / 4096);
}


x86 assembly (clang, -O0):
<_get_sector_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x120(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    118d <_get_sector_size+0x5d>
lea    -0x120(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1197 <_get_sector_size+0x67>
mov    -0x128(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x120(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c0 <_get_sector_size+0x90>
movl   $0x1,-0x4(%rbp)
jmp    11e5 <_get_sector_size+0xb5>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11d7 <_get_sector_size+0xa7>
movl   $0x1000,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x1000,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_get_sector_size>:
push   %rbx
sub    $0x110,%rsp
mov    %rdi,%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     115f <_get_sector_size+0x2f>
movb   $0x0,(%rax)
jmp    1170 <_get_sector_size+0x40>
lea    0xe9a(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     119c <_get_sector_size+0x6c>
mov    0x8(%rsp),%ecx
test   %ecx,%ecx
je     119c <_get_sector_size+0x6c>
lea    0xfff(%rcx),%eax
test   %ecx,%ecx
cmovns %ecx,%eax
sar    $0xc,%eax
jmp    11a1 <_get_sector_size+0x71>
mov    $0x1,%eax
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c".\00"
define i32 @_get_sector_size(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.stat
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca i8*
store i8* %0, i8** %3
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%13 = call i8* @strrchr(i8* %12, i8 signext 47)
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %22
19: ; preds = %1
%20 = load i8*, i8** %8
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 0, i8* %21
br label %22
22: ; preds = %19, %16
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%24 = call i32 @stat(i8* %23, %struct.stat* %5)
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 1, i32* %2
br label %37
28: ; preds = %22
%29 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%30 = load i32, i32* %29
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 4096, i32* %6
br label %34
34: ; preds = %33, %28
%35 = load i32, i32* %6
%36 = sdiv i32 %35, 4096
store i32 %36, i32* %2
br label %37
37: ; preds = %34, %27
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c".\00"
define i32 @_get_sector_size(i8* %0) {
%2 = alloca %struct.stat
%3 = alloca [256 x i8]
%4 = bitcast %struct.stat* %2 to i8*
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* %0)
%7 = call i8* @strrchr(i8* %5, i8 signext 47)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %12
11: ; preds = %1
store i8 0, i8* %7
br label %12
12: ; preds = %11, %9
%13 = call i32 @stat(i8* %5, %struct.stat* %2)
%14 = icmp eq i32 %13, -1
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 0
%19 = sdiv i32 %17, 4096
%20 = select i1 %18, i32 1, i32 %19
br label %21
21: ; preds = %12, %15
%22 = phi i32 [ %20, %15 ], [ 1, %12 ]
ret i32 %22
}