#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 /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
char *fwrite(char *, int, int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
void *strtod(char *, char **);
void main(int argc, char *argv[]) {
  FILE *fp;
  char *unit;
  int length = strtod(argv[1], &unit);
  char data = strtod(argv[2], NULL);
  char *buf;
  printf("total %d %s, padding data %x, name %s\n", length, unit, data & 0xFF,
         argv[3]);
  if (unit[0] == 0)
    length *= 1;
  else if (unit[0] == 'K' || unit[0] == 'k')
    length *= 1024;
  else if (unit[0] == 'M' || unit[0] == 'm')
    length *= (1024 * 1024);
  else if (unit[0] == 'G' || unit[0] == 'g')
    length *= (1024 * 1024);
  else {
    printf("unit %s is Not valid\n", unit);
    return;
  }
  fp = fopen(argv[3], "r+b");
  if (!fp)
    return;
  buf = malloc(length);
  memset(buf, data, length);
  printf("Original size %zd\n", fread(buf, 1, length, fp));
  fseek(fp, 0, SEEK_SET);
  printf("Padding  size %zd\n", fwrite(buf, 1, length, fp));
  free(buf);
  fclose(fp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <strtod@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <strtod@plt>
mov    %al,-0x25(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
movsbl -0x25(%rbp),%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%r8
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    121c <main+0x7c>
mov    -0x24(%rbp),%eax
shl    $0x0,%eax
mov    %eax,-0x24(%rbp)
jmp    12cc <main+0x12c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4b,%eax
je     123c <main+0x9c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6b,%eax
jne    124a <main+0xaa>
mov    -0x24(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x24(%rbp)
jmp    12c7 <main+0x127>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4d,%eax
je     126a <main+0xca>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6d,%eax
jne    1278 <main+0xd8>
mov    -0x24(%rbp),%eax
shl    $0x14,%eax
mov    %eax,-0x24(%rbp)
jmp    12c2 <main+0x122>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x47,%eax
je     1298 <main+0xf8>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x67,%eax
jne    12a6 <main+0x106>
mov    -0x24(%rbp),%eax
shl    $0x14,%eax
mov    %eax,-0x24(%rbp)
jmp    12bd <main+0x11d>
mov    -0x20(%rbp),%rsi
lea    0xd76(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1384 <main+0x1e4>
jmp    12c2 <main+0x122>
jmp    12c7 <main+0x127>
jmp    12cc <main+0x12c>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xd62(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12f4 <main+0x154>
jmp    1384 <main+0x1e4>
mov    -0x24(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x25(%rbp),%al
mov    -0x24(%rbp),%edx
movsbl %al,%esi
call   1080 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,%rsi
lea    0xd10(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2c9d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
mov    %rax,%rsi
lea    0xce9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
call   1050 <strtod@plt>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
xor    %esi,%esi
call   1050 <strtod@plt>
mov    %rax,%r14
mov    (%rsp),%r12
movzbl %r14b,%ecx
mov    0x18(%rbx),%r8
lea    0xe25(%rip),%rdi
mov    %r15d,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%r12),%al
lea    -0x47(%rax),%ecx
cmp    $0x26,%cl
ja     1233 <main+0x93>
movzbl %cl,%ecx
movabs $0x100000001,%rdx
bt     %rcx,%rdx
jb     1227 <main+0x87>
movabs $0x1000000010,%rdx
bt     %rcx,%rdx
jb     122d <main+0x8d>
movabs $0x4000000040,%rdx
bt     %rcx,%rdx
jae    1233 <main+0x93>
shl    $0x14,%r15d
jmp    123b <main+0x9b>
shl    $0xa,%r15d
jmp    123b <main+0x9b>
test   %al,%al
jne    12f3 <main+0x153>
mov    0x18(%rbx),%rdi
lea    0xdf7(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12e7 <main+0x147>
mov    %rax,%rbx
mov    %r15d,%edi
call   1090 <malloc@plt>
mov    %rax,%r12
movsbl %r14b,%esi
mov    %rax,%rdi
mov    %r15d,%edx
call   1080 <memset@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
lea    0xdb6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
lea    0xd92(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd2d(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1070 <printf@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"total %d %s, padding data %x, name %s\0A\00"
@.str.1 = [22 x i8] c"unit %s is Not valid\0A\00"
@.str.2 = [4 x i8] c"r+b\00"
@.str.3 = [19 x i8] c"Original size %zd\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [19 x i8] c"Padding size %zd\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = load i8**, i8*** %4
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i8* @strtod(i8* %12, i8** %6)
%14 = ptrtoint i8* %13 to i32
store i32 %14, i32* %7
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i8* @strtod(i8* %17, i8** null)
%19 = ptrtoint i8* %18 to i8
store i8 %19, i8* %8
%20 = load i32, i32* %7
%21 = load i8*, i8** %6
%22 = load i8, i8* %8
%23 = sext i8 %22 to i32
%24 = and i32 %23, 255
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 3
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %20, i8* %21, i32 %24, i8* %27)
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %2
%35 = load i32, i32* %7
%36 = mul nsw i32 %35, 1
store i32 %36, i32* %7
br label %88
37: ; preds = %2
%38 = load i8*, i8** %6
%39 = getelementptr inbounds i8, i8* %38, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 75
br i1 %42, label %49, label %43
43: ; preds = %37
%44 = load i8*, i8** %6
%45 = getelementptr inbounds i8, i8* %44, i64 0
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 107
br i1 %48, label %49, label %52
49: ; preds = %43, %37
%50 = load i32, i32* %7
%51 = mul nsw i32 %50, 1024
store i32 %51, i32* %7
br label %87
52: ; preds = %43
%53 = load i8*, i8** %6
%54 = getelementptr inbounds i8, i8* %53, i64 0
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 77
br i1 %57, label %64, label %58
58: ; preds = %52
%59 = load i8*, i8** %6
%60 = getelementptr inbounds i8, i8* %59, i64 0
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 109
br i1 %63, label %64, label %67
64: ; preds = %58, %52
%65 = load i32, i32* %7
%66 = mul nsw i32 %65, 1048576
store i32 %66, i32* %7
br label %86
67: ; preds = %58
%68 = load i8*, i8** %6
%69 = getelementptr inbounds i8, i8* %68, i64 0
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp eq i32 %71, 71
br i1 %72, label %79, label %73
73: ; preds = %67
%74 = load i8*, i8** %6
%75 = getelementptr inbounds i8, i8* %74, i64 0
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp eq i32 %77, 103
br i1 %78, label %79, label %82
79: ; preds = %73, %67
%80 = load i32, i32* %7
%81 = mul nsw i32 %80, 1048576
store i32 %81, i32* %7
br label %85
82: ; preds = %73
%83 = load i8*, i8** %6
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %83)
br label %120
85: ; preds = %79
br label %86
86: ; preds = %85, %64
br label %87
87: ; preds = %86, %49
br label %88
88: ; preds = %87, %34
%89 = load i8**, i8*** %4
%90 = getelementptr inbounds i8*, i8** %89, i64 3
%91 = load i8*, i8** %90
%92 = call i32* @fopen(i8* %91, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32* %92, i32** %5
%93 = load i32*, i32** %5
%94 = icmp ne i32* %93, null
br i1 %94, label %96, label %95
95: ; preds = %88
br label %120
96: ; preds = %88
%97 = load i32, i32* %7
%98 = call i8* @malloc(i32 %97)
store i8* %98, i8** %9
%99 = load i8*, i8** %9
%100 = load i8, i8* %8
%101 = load i32, i32* %7
%102 = call i32 @memset(i8* %99, i8 signext %100, i32 %101)
%103 = load i8*, i8** %9
%104 = load i32, i32* %7
%105 = load i32*, i32** %5
%106 = call i8* @fread(i8* %103, i32 1, i32 %104, i32* %105)
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %106)
%108 = load i32*, i32** %5
%109 = load i32, i32* @SEEK_SET
%110 = call i32 @fseek(i32* %108, i32 0, i32 %109)
%111 = load i8*, i8** %9
%112 = load i32, i32* %7
%113 = load i32*, i32** %5
%114 = call i8* @fwrite(i8* %111, i32 1, i32 %112, i32* %113)
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %114)
%116 = load i8*, i8** %9
%117 = call i32 @free(i8* %116)
%118 = load i32*, i32** %5
%119 = call i32 @fclose(i32* %118)
br label %120
120: ; preds = %96, %95, %82
ret void
}

LLVM IR (-O2):
@.str = [39 x i8] c"total %d %s, padding data %x, name %s\0A\00"
@.str.1 = [22 x i8] c"unit %s is Not valid\0A\00"
@.str.2 = [4 x i8] c"r+b\00"
@.str.3 = [19 x i8] c"Original size %zd\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [19 x i8] c"Padding size %zd\0A\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = call i8* @strtod(i8* %6, i8** %3)
%8 = ptrtoint i8* %7 to i64
%9 = trunc i64 %8 to i32
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i8* @strtod(i8* nocapture %11, i8** null)
%13 = ptrtoint i8* %12 to i64
%14 = trunc i64 %13 to i8
%15 = load i8*, i8** %3
%16 = trunc i64 %13 to i32
%17 = and i32 %16, 255
%18 = getelementptr inbounds i8*, i8** %1, i64 3
%19 = load i8*, i8** %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %9, i8* %15, i32 %17, i8* %19)
%21 = load i8, i8* %15
switch i8 %21, label %28 [
i8 0, label %30
i8 75, label %22
i8 107, label %22
i8 77, label %24
i8 109, label %24
i8 71, label %26
i8 103, label %26
]
22: ; preds = %2, %2
%23 = shl nsw i32 %9, 10
br label %30
24: ; preds = %2, %2
%25 = shl nsw i32 %9, 20
br label %30
26: ; preds = %2, %2
%27 = shl nsw i32 %9, 20
br label %30
28: ; preds = %2
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %46
30: ; preds = %2, %22, %26, %24
%31 = phi i32 [ %23, %22 ], [ %25, %24 ], [ %27, %26 ], [ %9, %2 ]
%32 = load i8*, i8** %18
%33 = tail call i32* @fopen(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %46, label %35
35: ; preds = %30
%36 = tail call i8* @malloc(i32 %31)
%37 = tail call i32 @memset(i8* %36, i8 signext %14, i32 %31)
%38 = tail call i8* @fread(i8* %36, i32 1, i32 %31, i32* %33)
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%40 = load i32, i32* @SEEK_SET
%41 = tail call i32 @fseek(i32* %33, i32 0, i32 %40)
%42 = tail call i8* @fwrite(i8* %36, i32 1, i32 %31, i32* %33)
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%44 = tail call i32 @free(i8* %36)
%45 = tail call i32 @fclose(i32* %33)
br label %46
46: ; preds = %30, %35, %28
ret void
}