#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ memcpy(unsigned char *, char *, int);
int write_array_elmt(FILE *fp, char *string, int string_len, char *label) {
  unsigned char buf[1024];
  int len;
  int i;
  memcpy(buf, (char *)string, string_len);
  len = string_len;
  fprintf(fp, "block.append(\"");
  for (i = 0; i < len; i++) {
    fprintf(fp, "\\x%02x", buf[i]);
  }
  fprintf(fp, "\")\n");
}


x86 assembly (clang, -O0):
<write_array_elmt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x434(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x438(%rbp)
mov    -0x438(%rbp),%eax
cmp    -0x434(%rbp),%eax
jge    11b9 <write_array_elmt+0x99>
mov    -0x10(%rbp),%rdi
movslq -0x438(%rbp),%rax
movzbl -0x430(%rbp,%rax,1),%edx
ff
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x438(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x438(%rbp)
jmp    1172 <write_array_elmt+0x52>
mov    -0x10(%rbp),%rdi
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_array_elmt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %edx,%ebp
mov    %rdi,%r15
mov    %rsp,%rdi
call   1040 <memcpy@plt>
lea    0xeaf(%rip),%rdi
mov    $0xe,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fwrite@plt>
test   %ebp,%ebp
jle    119a <write_array_elmt+0x6a>
mov    %ebp,%ebp
lea    0xe9f(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rsp,%rbx,1),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <write_array_elmt+0x50>
lea    0xe75(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fwrite@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"block.append(\22\00"
@.str.1 = [7 x i8] c"\\x%02x\00"
@.str.2 = [4 x i8] c"\22)\0A\00"
define i32 @write_array_elmt(i32* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [1024 x i8]
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%14 = load i8*, i8** %7
%15 = load i32, i32* %8
%16 = call i32 @memcpy(i8* %13, i8* %14, i32 %15)
%17 = load i32, i32* %8
store i32 %17, i32* %11
%18 = load i32*, i32** %6
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %12
br label %20
20: ; preds = %32, %4
%21 = load i32, i32* %12
%22 = load i32, i32* %11
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %35
24: ; preds = %20
%25 = load i32*, i32** %6
%26 = load i32, i32* %12
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %24
%33 = load i32, i32* %12
%34 = add nsw i32 %33, 1
store i32 %34, i32* %12
br label %20
35: ; preds = %20
%36 = load i32*, i32** %6
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
@.str = [15 x i8] c"block.append(\22\00"
@.str.1 = [7 x i8] c"\\x%02x\00"
@.str.2 = [4 x i8] c"\22)\0A\00"
define i32 @write_array_elmt(i32* nocapture %0, i8* %1, i32 %2, i8* nocapture readnone %3) {
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = call i32 @memcpy(i8* %6, i8* %1, i32 %2)
%8 = call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 14, i64 1, i32* %0)
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %20
10: ; preds = %4
%11 = zext i32 %2 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %18, %12 ]
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = add nuw nsw i64 %13, 1
%19 = icmp eq i64 %18, %11
br i1 %19, label %20, label %12
20: ; preds = %12, %4
%21 = call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3, i64 1, i32* %0)
ret i32 undef
}