#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int get_sd_block_count(char *devicefile) {
  FILE *fp;
  char buf[128];
  int block_count = 0;
  int nbytes = 0;
  char *t = "/sys/block/";
  char sd_size_file[64];
  strcpy(sd_size_file, t);
  strcat(sd_size_file, &devicefile[5]);
  strcat(sd_size_file, "/size");
  fp = fopen(sd_size_file, "rb");
  nbytes = fread(buf, 1, 128, fp);
  fclose(fp);
  block_count = atoi(buf);
  return block_count;
}


x86 assembly (clang, -O0):
<get_sd_block_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
lea    0xe76(%rip),%rax
mov    %rax,-0xa0(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0xe0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x5,%rsi
call   1080 <strcat@plt>
lea    -0xe0(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1080 <strcat@plt>
lea    -0xe0(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x80,%edx
call   1040 <fread@plt>
mov    %eax,-0x98(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x90(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sd_block_count>:
push   %r14
push   %rbx
sub    $0xc8,%rsp
mov    %rdi,%rbx
lea    0xe8c(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
add    $0x5,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
lea    0xe77(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
lea    0xe6e(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0x40(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x80,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1070 <atoi@plt>
add    $0xc8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/sys/block/\00"
@.str.1 = [6 x i8] c"/size\00"
@.str.2 = [3 x i8] c"rb\00"
define i32 @get_sd_block_count(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [128 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [64 x i8]
store i8* %0, i8** %2
store i32 0, i32* %5
store i32 0, i32* %6
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%10 = load i8*, i8** %7
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 5
%15 = call i32 @strcat(i8* %12, i8* %14)
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%17 = call i32 @strcat(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %19, i32** %3
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%21 = load i32*, i32** %3
%22 = call i32 @fread(i8* %20, i32 1, i32 128, i32* %21)
store i32 %22, i32* %6
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %5
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
@.str = [12 x i8] c"/sys/block/\00"
@.str.1 = [6 x i8] c"/size\00"
@.str.2 = [3 x i8] c"rb\00"
define i32 @get_sd_block_count(i8* %0) {
%2 = alloca [128 x i8]
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds i8, i8* %0, i64 5
%8 = call i32 @strcat(i8* %5, i8* %7)
%9 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @fread(i8* %4, i32 1, i32 128, i32* %10)
%12 = call i32 @fclose(i32* %10)
%13 = call i32 @atoi(i8* %4)
ret i32 %13
}