#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 atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int rdsize(char *x) {
  int ll, v;
  char cp[32];
  ll = strlen(x) - 1;
  strcpy(cp, x);
  switch (x[ll]) {
  case 'b':
    cp[ll] = 0;
    v = atoi(cp);
    v *= 512;
    break;
  case 'K':
  case 'k':
    cp[ll] = 0;
    v = atoi(cp);
    v *= 1024;
    break;
  default:
    v = atoi(cp);
  }
  if (v % 512) {
    fprintf(stderr, "sizes must be multiples of 512 bytes (block size)\n");
    v = -1;
  }
  if (v < 0)
    v = -1;
  return v;
}


x86 assembly (clang, -O0):
<rdsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    -0x30(%rbp),%rdi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x34(%rbp)
sub    $0x4b,%eax
je     11ca <rdsize+0x8a>
jmp    1185 <rdsize+0x45>
mov    -0x34(%rbp),%eax
sub    $0x62,%eax
je     11a7 <rdsize+0x67>
jmp    1196 <rdsize+0x56>
mov    -0x34(%rbp),%eax
sub    $0x6b,%eax
je     11ca <rdsize+0x8a>
jmp    11ed <rdsize+0xad>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x9,%eax
mov    %eax,-0x10(%rbp)
jmp    11f9 <rdsize+0xb9>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x10(%rbp)
jmp    11f9 <rdsize+0xb9>
lea    -0x30(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x200,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1229 <rdsize+0xe9>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    123a <rdsize+0xfa>
movl   $0xffffffff,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rdsize>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
call   1040 <strlen@plt>
movslq %eax,%r14
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
movsbl -0x1(%r14,%rbx,1),%eax
cmp    $0x4b,%eax
je     118c <rdsize+0x4c>
cmp    $0x6b,%eax
je     118c <rdsize+0x4c>
cmp    $0x62,%eax
jne    11c0 <rdsize+0x80>
movb   $0x0,-0x1(%rsp,%r14,1)
mov    %rsp,%rdi
call   1060 <atoi@plt>
shl    $0x9,%eax
test   $0x1ff,%eax
jne    11a4 <rdsize+0x64>
jmp    11cf <rdsize+0x8f>
movb   $0x0,-0x1(%rsp,%r14,1)
mov    %rsp,%rdi
call   1060 <atoi@plt>
shl    $0xa,%eax
test   $0x1ff,%eax
je     11cf <rdsize+0x8f>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ecx
jmp    11d9 <rdsize+0x99>
mov    %rsp,%rdi
call   1060 <atoi@plt>
test   $0x1ff,%eax
jne    11a4 <rdsize+0x64>
test   %eax,%eax
mov    $0xffffffff,%ecx
cmovns %eax,%ecx
mov    %ecx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [51 x i8] c"sizes must be multiples of 512 bytes (block size)\0A\00"
define i32 @rdsize(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [32 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = sub nsw i32 %7, 1
store i32 %8, i32* %3
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%10 = load i8*, i8** %2
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = load i8*, i8** %2
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
switch i32 %17, label %34 [
i32 98, label %18
i32 75, label %26
i32 107, label %26
]
18: ; preds = %1
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 %20
store i8 0, i8* %21
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = mul nsw i32 %24, 512
store i32 %25, i32* %4
br label %37
26: ; preds = %1, %1
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 %28
store i8 0, i8* %29
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %4
%32 = load i32, i32* %4
%33 = mul nsw i32 %32, 1024
store i32 %33, i32* %4
br label %37
34: ; preds = %1
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %4
br label %37
37: ; preds = %34, %26, %18
%38 = load i32, i32* %4
%39 = srem i32 %38, 512
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %44
44: ; preds = %41, %37
%45 = load i32, i32* %4
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %44
store i32 -1, i32* %4
br label %48
48: ; preds = %47, %44
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [51 x i8] c"sizes must be multiples of 512 bytes (block size)\0A\00"
define i32 @rdsize(i8* %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, -1
%6 = call i32 @strcpy(i8* %3, i8* %0)
%7 = sext i32 %5 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
switch i32 %10, label %19 [
i32 98, label %11
i32 75, label %15
i32 107, label %15
]
11: ; preds = %1
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %7
store i8 0, i8* %12
%13 = call i32 @atoi(i8* %3)
%14 = shl nsw i32 %13, 9
br label %21
15: ; preds = %1, %1
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %7
store i8 0, i8* %16
%17 = call i32 @atoi(i8* %3)
%18 = shl nsw i32 %17, 10
br label %21
19: ; preds = %1
%20 = call i32 @atoi(i8* %3)
br label %21
21: ; preds = %19, %15, %11
%22 = phi i32 [ %20, %19 ], [ %18, %15 ], [ %14, %11 ]
%23 = and i32 %22, 511
%24 = icmp eq i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %31
28: ; preds = %21
%29 = icmp sgt i32 %22, -1
%30 = select i1 %29, i32 %22, i32 -1
br label %31
31: ; preds = %28, %25
%32 = phi i32 [ -1, %25 ], [ %30, %28 ]
ret i32 %32
}