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

/* Variables and functions */
int blob_pad_len(struct blob_attr *);
int blob_raw_len(struct blob_attr *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
void blob_fill_pad(struct blob_attr *attr) {
  char *buf = (char *)attr;
  int len = blob_pad_len(attr);
  int delta = len - blob_raw_len(attr);
  if (delta > 0)
    memset(buf + len - delta, 0, delta);
}


x86 assembly (clang, -O0):
<blob_fill_pad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <blob_pad_len@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <blob_raw_len@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1194 <blob_fill_pad+0x64>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
movslq -0x18(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blob_fill_pad>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <blob_pad_len@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <blob_raw_len@plt>
mov    %ebp,%edx
sub    %eax,%edx
jle    1166 <blob_fill_pad+0x36>
movslq %ebp,%rax
add    %rax,%rbx
mov    %edx,%eax
sub    %rax,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <memset@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.blob_attr = type { i32 }
define void @blob_fill_pad(%struct.blob_attr* %0) {
%2 = alloca %struct.blob_attr*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store %struct.blob_attr* %0, %struct.blob_attr** %2
%6 = load %struct.blob_attr*, %struct.blob_attr** %2
%7 = bitcast %struct.blob_attr* %6 to i8*
store i8* %7, i8** %3
%8 = load %struct.blob_attr*, %struct.blob_attr** %2
%9 = call i32 @blob_pad_len(%struct.blob_attr* %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = load %struct.blob_attr*, %struct.blob_attr** %2
%12 = call i32 @blob_raw_len(%struct.blob_attr* %11)
%13 = sub nsw i32 %10, %12
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = sub i64 0, %22
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i32, i32* %5
%26 = call i32 @memset(i8* %24, i32 0, i32 %25)
br label %27
27: ; preds = %16, %1
ret void
}

LLVM IR (-O2):
%struct.blob_attr = type { i32 }
define void @blob_fill_pad(%struct.blob_attr* %0) {
%2 = tail call i32 @blob_pad_len(%struct.blob_attr* %0)
%3 = tail call i32 @blob_raw_len(%struct.blob_attr* %0)
%4 = sub nsw i32 %2, %3
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = bitcast %struct.blob_attr* %0 to i8*
%8 = sext i32 %2 to i64
%9 = getelementptr inbounds i8, i8* %7, i64 %8
%10 = zext i32 %4 to i64
%11 = sub nsw i64 0, %10
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = tail call i32 @memset(i8* %12, i32 0, i32 %4)
br label %14
14: ; preds = %6, %1
ret void
}