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

/* Variables and functions */
char EXIT_SUCCESS;
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(long);
int /*<<< orphan*/ memset(char *, int, long);
char mem_worker(long num_bytes, long touch, struct timespec *delay_ptr) {
  char *str;
  str = (char *)malloc(num_bytes);
  if (num_bytes >= touch) {
    memset(str, 0xFF, touch);
    memset(str, 0x00, touch);
  } else {
    memset(str, 0xFF, num_bytes);
    memset(str, 0x00, num_bytes);
  }
  free(str);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<mem_worker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jl     1185 <mem_worker+0x55>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xff,%esi
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
jmp    11a6 <mem_worker+0x76>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0xff,%esi
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2e2a(%rip),%rax
movsbl (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_worker>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
call   1050 <malloc@plt>
mov    %rax,%r15
cmp    %rbx,%r14
cmovl  %r14,%rbx
mov    %rax,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1040 <memset@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <memset@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%al
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@EXIT_SUCCESS = global i8 0
define signext i8 @mem_worker(i64 %0, i64 %1, %struct.timespec* %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca %struct.timespec*
%7 = alloca i8*
store i64 %0, i64* %4
store i64 %1, i64* %5
store %struct.timespec* %2, %struct.timespec** %6
%8 = load i64, i64* %4
%9 = call i64 @malloc(i64 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %7
%11 = load i64, i64* %4
%12 = load i64, i64* %5
%13 = icmp sge i64 %11, %12
br i1 %13, label %14, label %21
14: ; preds = %3
%15 = load i8*, i8** %7
%16 = load i64, i64* %5
%17 = call i32 @memset(i8* %15, i32 255, i64 %16)
%18 = load i8*, i8** %7
%19 = load i64, i64* %5
%20 = call i32 @memset(i8* %18, i32 0, i64 %19)
br label %28
21: ; preds = %3
%22 = load i8*, i8** %7
%23 = load i64, i64* %4
%24 = call i32 @memset(i8* %22, i32 255, i64 %23)
%25 = load i8*, i8** %7
%26 = load i64, i64* %4
%27 = call i32 @memset(i8* %25, i32 0, i64 %26)
br label %28
28: ; preds = %21, %14
%29 = load i8*, i8** %7
%30 = call i32 @free(i8* %29)
%31 = load i8, i8* @EXIT_SUCCESS
ret i8 %31
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@EXIT_SUCCESS = global i8 0
define signext i8 @mem_worker(i64 %0, i64 %1, %struct.timespec* nocapture readnone %2) {
%4 = tail call i64 @malloc(i64 %0)
%5 = inttoptr i64 %4 to i8*
%6 = icmp slt i64 %0, %1
%7 = select i1 %6, i64 %0, i64 %1
%8 = tail call i32 @memset(i8* %5, i32 255, i64 %7)
%9 = tail call i32 @memset(i8* %5, i32 0, i64 %7)
%10 = tail call i32 @free(i8* %5)
%11 = load i8, i8* @EXIT_SUCCESS
ret i8 %11
}