#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*/ fseek(int /*<<< orphan*/ *, unsigned int,
                         int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, unsigned int);
unsigned int strlen(char *);
void patchUStr(FILE *f, unsigned int at, char *str, unsigned int maxlen) {
  char data[maxlen];
  memset(data, 0, maxlen);
  unsigned int i, j;
  unsigned int len = strlen(str);
  for (i = 0, j = 0; (i < len) && (j < maxlen); i++, j += 2) {
    data[j] = str[i];
    data[j + 1] = 0;
  }
  fseek(f, at, SEEK_SET);
  fwrite(data, 1, maxlen, f);
}


x86 assembly (clang, -O0):
<patchUStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x34(%rbp),%ecx
xor    %eax,%eax
cmp    -0x3c(%rbp),%ecx
mov    %al,-0x49(%rbp)
jae    11bd <patchUStr+0x7d>
mov    -0x38(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setb   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    11cd <patchUStr+0x8d>
jmp    1204 <patchUStr+0xc4>
mov    -0x48(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x34(%rbp),%edx
mov    (%rcx,%rdx,1),%dl
mov    -0x38(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x38(%rbp)
jmp    11a0 <patchUStr+0x60>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2dce(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    -0x48(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<patchUStr>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %esi,%r15d
mov    %rdi,%r14
mov    %ecx,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ecx,%edx
call   1040 <memset@plt>
mov    %r13,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     11c6 <patchUStr+0x86>
test   %r12d,%r12d
je     11c6 <patchUStr+0x86>
mov    %eax,%edi
mov    $0x1,%ecx
mov    $0x2,%edx
cs nopw 0x0(%rax,%rax,1)
lea    -0x2(%rdx),%esi
movzbl -0x1(%r13,%rcx,1),%eax
mov    %al,(%rbx,%rsi,1)
lea    -0x1(%rdx),%eax
movb   $0x0,(%rbx,%rax,1)
cmp    %rdi,%rcx
jae    11c6 <patchUStr+0x86>
add    $0x1,%rcx
lea    0x2(%rdx),%eax
cmp    %r12d,%edx
mov    %eax,%edx
jb     11a0 <patchUStr+0x60>
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r15d,%esi
call   1050 <fseek@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define void @patchUStr(i32* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%14 = load i32, i32* %8
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %9
%17 = alloca i8, i64 %15
store i64 %15, i64* %10
%18 = load i32, i32* %8
%19 = call i32 @memset(i8* %17, i32 0, i32 %18)
%20 = load i8*, i8** %7
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %13
store i32 0, i32* %11
store i32 0, i32* %12
br label %22
22: ; preds = %45, %4
%23 = load i32, i32* %11
%24 = load i32, i32* %13
%25 = icmp ult i32 %23, %24
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* %12
%28 = load i32, i32* %8
%29 = icmp ult i32 %27, %28
br label %30
30: ; preds = %26, %22
%31 = phi i1 [ false, %22 ], [ %29, %26 ]
br i1 %31, label %32, label %50
32: ; preds = %30
%33 = load i8*, i8** %7
%34 = load i32, i32* %11
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = load i32, i32* %12
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %17, i64 %39
store i8 %37, i8* %40
%41 = load i32, i32* %12
%42 = add i32 %41, 1
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %17, i64 %43
store i8 0, i8* %44
br label %45
45: ; preds = %32
%46 = load i32, i32* %11
%47 = add i32 %46, 1
store i32 %47, i32* %11
%48 = load i32, i32* %12
%49 = add i32 %48, 2
store i32 %49, i32* %12
br label %22
50: ; preds = %30
%51 = load i32*, i32** %5
%52 = load i32, i32* %6
%53 = load i32, i32* @SEEK_SET
%54 = call i32 @fseek(i32* %51, i32 %52, i32 %53)
%55 = load i32, i32* %8
%56 = load i32*, i32** %5
%57 = call i32 @fwrite(i8* %17, i32 1, i32 %55, i32* %56)
%58 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define void @patchUStr(i32* nocapture %0, i32 %1, i8* %2, i32 %3) {
%5 = zext i32 %3 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @memset(i8* %6, i32 0, i32 %3)
%8 = call i32 @strlen(i8* %2)
%9 = icmp ne i32 %8, 0
%10 = icmp ne i32 %3, 0
%11 = and i1 %9, %10
br i1 %11, label %12, label %29
12: ; preds = %4
%13 = zext i32 %8 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %24, %14 ]
%16 = phi i32 [ 0, %12 ], [ %25, %14 ]
%17 = getelementptr inbounds i8, i8* %2, i64 %15
%18 = load i8, i8* %17
%19 = zext i32 %16 to i64
%20 = getelementptr inbounds i8, i8* %6, i64 %19
store i8 %18, i8* %20
%21 = or i32 %16, 1
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %6, i64 %22
store i8 0, i8* %23
%24 = add nuw nsw i64 %15, 1
%25 = add i32 %16, 2
%26 = icmp ult i64 %24, %13
%27 = icmp ult i32 %25, %3
%28 = select i1 %26, i1 %27, i1 false
br i1 %28, label %14, label %29
29: ; preds = %14, %4
%30 = load i32, i32* @SEEK_SET
%31 = call i32 @fseek(i32* %0, i32 %1, i32 %30)
%32 = call i32 @fwrite(i8* %6, i32 1, i32 %3, i32* %0)
ret void
}