#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*/ puts(char *);
int scan_hexnum(unsigned int *);
void fill_mem() {
  unsigned char *p;
  unsigned int len;
  unsigned int val;
  int ii;
  if (scan_hexnum((unsigned *)&p) == 0x0) {
    if (scan_hexnum(&len) == 0x0) {
      if (scan_hexnum(&val) == 0x0) {
        for (ii = 0; ii < len; ii++) {
          p[ii] = (unsigned char)val;
        }
        return;
      }
    }
  }
  puts("Invalid arguments\n");
}


x86 assembly (clang, -O0):
<fill_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
call   1040 <scan_hexnum@plt>
cmp    $0x0,%eax
jne    119e <fill_mem+0x7e>
lea    -0xc(%rbp),%rdi
call   1040 <scan_hexnum@plt>
cmp    $0x0,%eax
jne    1199 <fill_mem+0x79>
lea    -0x10(%rbp),%rdi
call   1040 <scan_hexnum@plt>
cmp    $0x0,%eax
jne    1194 <fill_mem+0x74>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    118f <fill_mem+0x6f>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1165 <fill_mem+0x45>
jmp    11aa <fill_mem+0x8a>
jmp    1199 <fill_mem+0x79>
jmp    119e <fill_mem+0x7e>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_mem>:
sub    $0x18,%rsp
lea    0x10(%rsp),%rdi
call   1040 <scan_hexnum@plt>
test   %eax,%eax
jne    114e <fill_mem+0x2e>
lea    0x8(%rsp),%rdi
call   1040 <scan_hexnum@plt>
test   %eax,%eax
jne    114e <fill_mem+0x2e>
lea    0xc(%rsp),%rdi
call   1040 <scan_hexnum@plt>
test   %eax,%eax
je     115f <fill_mem+0x3f>
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
ret
cmpl   $0x0,0x8(%rsp)
je     115a <fill_mem+0x3a>
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movzbl 0xc(%rsp),%ecx
mov    0x10(%rsp),%rdx
mov    %cl,(%rdx,%rax,1)
add    $0x1,%rax
mov    0x8(%rsp),%ecx
cmp    %rcx,%rax
jb     1170 <fill_mem+0x50>
jmp    115a <fill_mem+0x3a>

LLVM IR (-O0):
@.str = [19 x i8] c"Invalid arguments\0A\00"
define void @fill_mem() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i8** %1 to i32*
%6 = call i32 @scan_hexnum(i32* %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %32
8: ; preds = %0
%9 = call i32 @scan_hexnum(i32* %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %31
11: ; preds = %8
%12 = call i32 @scan_hexnum(i32* %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %30
14: ; preds = %11
store i32 0, i32* %4
br label %15
15: ; preds = %26, %14
%16 = load i32, i32* %4
%17 = load i32, i32* %2
%18 = icmp ult i32 %16, %17
br i1 %18, label %19, label %29
19: ; preds = %15
%20 = load i32, i32* %3
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %1
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 %21, i8* %25
br label %26
26: ; preds = %19
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %15
29: ; preds = %15
br label %34
30: ; preds = %11
br label %31
31: ; preds = %30, %8
br label %32
32: ; preds = %31, %0
%33 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"Invalid arguments\0A\00"
define void @fill_mem() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i8** %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = bitcast i8** %1 to i32*
%8 = call i32 @scan_hexnum(i32* %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %29
10: ; preds = %0
%11 = call i32 @scan_hexnum(i32* %2)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = call i32 @scan_hexnum(i32* %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, 0
br i1 %18, label %31, label %19
19: ; preds = %16, %19
%20 = phi i64 [ %25, %19 ], [ 0, %16 ]
%21 = load i32, i32* %3
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %1
%24 = getelementptr inbounds i8, i8* %23, i64 %20
store i8 %22, i8* %24
%25 = add nuw nsw i64 %20, 1
%26 = load i32, i32* %2
%27 = zext i32 %26 to i64
%28 = icmp ult i64 %25, %27
br i1 %28, label %19, label %31
29: ; preds = %10, %13, %0
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %19, %16, %29
ret void
}