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


x86 assembly (clang, -O0):
<patchAStr>:
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,-0x40(%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,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
xor    %eax,%eax
cmp    -0x38(%rbp),%ecx
mov    %al,-0x41(%rbp)
jae    11bb <patchAStr+0x7b>
mov    -0x34(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
setb   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    11cb <patchAStr+0x8b>
jmp    11ed <patchAStr+0xad>
mov    -0x40(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x34(%rbp),%edx
mov    (%rcx,%rdx,1),%dl
mov    -0x34(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1199 <patchAStr+0x59>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2de5(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    -0x40(%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):
<patchAStr>:
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     11ba <patchAStr+0x6a>
cmp    $0x1,%r12d
je     11ba <patchAStr+0x6a>
add    $0xffffffff,%eax
lea    -0x2(%r12),%ecx
cmp    %ecx,%eax
cmovae %ecx,%eax
add    $0x1,%rax
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rax,%rdx
call   1050 <memcpy@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r15d,%esi
call   1060 <fseek@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %r14,%rcx
call   1070 <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 @patchAStr(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
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%13 = load i32, i32* %8
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %9
%16 = alloca i8, i64 %14
store i64 %14, i64* %10
%17 = load i32, i32* %8
%18 = call i32 @memset(i8* %16, i32 0, i32 %17)
%19 = load i8*, i8** %7
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %12
store i32 0, i32* %11
br label %21
21: ; preds = %41, %4
%22 = load i32, i32* %11
%23 = load i32, i32* %12
%24 = icmp ult i32 %22, %23
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i32, i32* %11
%27 = load i32, i32* %8
%28 = sub i32 %27, 1
%29 = icmp ult i32 %26, %28
br label %30
30: ; preds = %25, %21
%31 = phi i1 [ false, %21 ], [ %29, %25 ]
br i1 %31, label %32, label %44
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* %11
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %16, i64 %39
store i8 %37, i8* %40
br label %41
41: ; preds = %32
%42 = load i32, i32* %11
%43 = add i32 %42, 1
store i32 %43, i32* %11
br label %21
44: ; preds = %30
%45 = load i32*, i32** %5
%46 = load i32, i32* %6
%47 = load i32, i32* @SEEK_SET
%48 = call i32 @fseek(i32* %45, i32 %46, i32 %47)
%49 = load i32, i32* %8
%50 = load i32*, i32** %5
%51 = call i32 @fwrite(i8* %16, i32 1, i32 %49, i32* %50)
%52 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define void @patchAStr(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, 1
%11 = and i1 %9, %10
br i1 %11, label %12, label %18
12: ; preds = %4
%13 = add i32 %8, -1
%14 = add i32 %3, -2
%15 = call i32 @llvm.umin.i32(i32 %13, i32 %14)
%16 = zext i32 %15 to i64
%17 = add nuw nsw i64 %16, 1
br label %18
18: ; preds = %12, %4
%19 = load i32, i32* @SEEK_SET
%20 = call i32 @fseek(i32* %0, i32 %1, i32 %19)
%21 = call i32 @fwrite(i8* %6, i32 1, i32 %3, i32* %0)
ret void
}