#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*/ printf(char *, ...);
int /*<<< orphan*/ write(int, char *, int);
int AdjustInSectorSize(int iFd, int iSourceSize) {
  int i;
  int iAdjustSizeToSector;
  char cCh;
  int iSectorCount;
  iAdjustSizeToSector = iSourceSize % 512;
  cCh = 0x00;
  if (iAdjustSizeToSector != 0) {
    iAdjustSizeToSector = 512 - iAdjustSizeToSector;
    printf("[INFO] File size [%d] and fill [%d] byte\n", iSourceSize,
           iAdjustSizeToSector);
    for (i = 0; i < iAdjustSizeToSector; i++) {
      write(iFd, &cCh, 1);
    }
  } else {
    printf("[INFO] File size is aligned 512 byte\n");
  }
  iSectorCount = (iSourceSize + iAdjustSizeToSector) / 512;
  return iSectorCount;
}


x86 assembly (clang, -O0):
<AdjustInSectorSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x200,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11a0 <AdjustInSectorSize+0x80>
mov    $0x200,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    119b <AdjustInSectorSize+0x7b>
mov    -0x4(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1170 <AdjustInSectorSize+0x50>
jmp    11ae <AdjustInSectorSize+0x8e>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x200,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AdjustInSectorSize>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r15d
lea    0x1ff(%r15),%eax
test   %esi,%esi
cmovns %esi,%eax
and    $0xfffffe00,%eax
mov    %esi,%ebx
movb   $0x0,0xf(%rsp)
sub    %eax,%ebx
je     11a5 <AdjustInSectorSize+0x75>
mov    %edi,%ebp
mov    $0x200,%r14d
sub    %ebx,%r14d
lea    0xe93(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xfffffe00,%ebx
lea    0xf(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
inc    %ebx
jne    1190 <AdjustInSectorSize+0x60>
jmp    11b4 <AdjustInSectorSize+0x84>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
mov    %r14d,%ecx
add    %r15d,%ecx
lea    0x1ff(%r14,%r15,1),%eax
cmovns %ecx,%eax
sar    $0x9,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"[INFO] File size [%d] and fill [%d] byte\0A\00"
@.str.1 = [38 x i8] c"[INFO] File size is aligned 512 byte\0A\00"
define i32 @AdjustInSectorSize(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = srem i32 %9, 512
store i32 %10, i32* %6
store i8 0, i8* %7
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %30
13: ; preds = %2
%14 = load i32, i32* %6
%15 = sub nsw i32 512, %14
store i32 %15, i32* %6
%16 = load i32, i32* %4
%17 = load i32, i32* %6
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17)
store i32 0, i32* %5
br label %19
19: ; preds = %26, %13
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i32, i32* %3
%25 = call i32 @write(i32 %24, i8* %7, i32 1)
br label %26
26: ; preds = %23
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %19
29: ; preds = %19
br label %32
30: ; preds = %2
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %29
%33 = load i32, i32* %4
%34 = load i32, i32* %6
%35 = add nsw i32 %33, %34
%36 = sdiv i32 %35, 512
store i32 %36, i32* %8
%37 = load i32, i32* %8
ret i32 %37
}

LLVM IR (-O2):
@.str = [42 x i8] c"[INFO] File size [%d] and fill [%d] byte\0A\00"
@str = [37 x i8] c"[INFO] File size is aligned 512 byte\00"
define i32 @AdjustInSectorSize(i32 %0, i32 %1) {
%3 = alloca i8
%4 = srem i32 %1, 512
store i8 0, i8* %3
%5 = icmp eq i32 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %2
%7 = sub nsw i32 512, %4
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %7)
br label %9
9: ; preds = %6, %9
%10 = phi i32 [ %12, %9 ], [ 0, %6 ]
%11 = call i32 @write(i32 %0, i8* %3, i32 1)
%12 = add nuw nsw i32 %10, 1
%13 = icmp eq i32 %12, %7
br i1 %13, label %16, label %9
14: ; preds = %2
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %9, %14
%17 = phi i32 [ 0, %14 ], [ %7, %9 ]
%18 = add nsw i32 %17, %1
%19 = sdiv i32 %18, 512
ret i32 %19
}