#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);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
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);
    nanosleep(delay_ptr, NULL);
    memset(str, 0x00, touch);
  } else {
    memset(str, 0xFF, num_bytes);
    nanosleep(delay_ptr, NULL);
    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   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jl     11a2 <mem_worker+0x62>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xff,%esi
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <nanosleep@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
jmp    11d0 <mem_worker+0x90>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0xff,%esi
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <nanosleep@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2e00(%rip),%rax
movsbl (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_worker>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1060 <malloc@plt>
mov    %rax,%r12
cmp    %r15,%rbx
cmovl  %rbx,%r15
mov    %rax,%rdi
mov    $0xff,%esi
mov    %r15,%rdx
call   1050 <memset@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1050 <memset@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%al
add    $0x8,%rsp
pop    %rbx
pop    %r12
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 %23
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 %struct.timespec*, %struct.timespec** %6
%19 = call i32 @nanosleep(%struct.timespec* %18, i32* null)
%20 = load i8*, i8** %7
%21 = load i64, i64* %5
%22 = call i32 @memset(i8* %20, i32 0, i64 %21)
br label %32
23: ; preds = %3
%24 = load i8*, i8** %7
%25 = load i64, i64* %4
%26 = call i32 @memset(i8* %24, i32 255, i64 %25)
%27 = load %struct.timespec*, %struct.timespec** %6
%28 = call i32 @nanosleep(%struct.timespec* %27, i32* null)
%29 = load i8*, i8** %7
%30 = load i64, i64* %4
%31 = call i32 @memset(i8* %29, i32 0, i64 %30)
br label %32
32: ; preds = %23, %14
%33 = load i8*, i8** %7
%34 = call i32 @free(i8* %33)
%35 = load i8, i8* @EXIT_SUCCESS
ret i8 %35
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@EXIT_SUCCESS = global i8 0
define signext i8 @mem_worker(i64 %0, i64 %1, %struct.timespec* %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 @nanosleep(%struct.timespec* %2, i32* null)
%10 = tail call i32 @memset(i8* %5, i32 0, i64 %7)
%11 = tail call i32 @free(i8* %5)
%12 = load i8, i8* @EXIT_SUCCESS
ret i8 %12
}