#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 */

/* Variables and functions */
char *mk_var(char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ rcc_printf(char *, ...);
int strlen(char const *);
void emit_set_string(const char *dstvar, const char *str, int j) {
  int rest, off = 0;
  off = strlen(str) + 1;
  rest = (off % 4);
  if (rest)
    rest = 4 - rest;
  off += rest - 8;
  rcc_printf("  add pc, $%d\n", (off));
  rcc_printf(".string \"%s\"\n", str);
  if (rest)
    rcc_printf(".fill %d, 1, 0\n", (rest));
  rcc_printf("  sub r0, pc, $%d\n", off + 16);
  {
    char str[32], *p = mk_var(str, dstvar, 0);
    rcc_printf("  str r0, [%s]\n", p);
  }
}


x86 assembly (clang, -O0):
<emit_set_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     117c <emit_set_string+0x4c>
mov    $0x4,%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x8,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1050 <rcc_printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1050 <rcc_printf@plt>
cmpl   $0x0,-0x18(%rbp)
je     11c6 <emit_set_string+0x96>
mov    -0x18(%rbp),%esi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1050 <rcc_printf@plt>
mov    -0x1c(%rbp),%esi
add    $0x10,%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <rcc_printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1040 <mk_var@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <rcc_printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emit_set_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%ecx
lea    0x4(%rax),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
and    $0xfffffffc,%edx
neg    %edx
lea    (%rax,%rdx,1),%ecx
add    $0x1,%ecx
mov    $0x4,%ebx
sub    %ecx,%ebx
test   %ecx,%ecx
cmove  %ecx,%ebx
lea    (%rax,%rbx,1),%ebp
add    $0xfffffff9,%ebp
lea    0xe89(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <rcc_printf@plt>
lea    0xe88(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <rcc_printf@plt>
test   %ebx,%ebx
je     11a5 <emit_set_string+0x75>
lea    0xe81(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <rcc_printf@plt>
add    $0x10,%ebp
lea    0xe7e(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <rcc_printf@plt>
mov    %rsp,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <mk_var@plt>
lea    0xe74(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <rcc_printf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c" add pc, $%d\0A\00"
@.str.1 = [14 x i8] c".string \22%s\22\0A\00"
@.str.2 = [16 x i8] c".fill %d, 1, 0\0A\00"
@.str.3 = [19 x i8] c" sub r0, pc, $%d\0A\00"
@.str.4 = [16 x i8] c" str r0, [%s]\0A\00"
define void @emit_set_string(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [32 x i8]
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %8
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 1
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = srem i32 %14, 4
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load i32, i32* %7
%20 = sub nsw i32 4, %19
store i32 %20, i32* %7
br label %21
21: ; preds = %18, %3
%22 = load i32, i32* %7
%23 = sub nsw i32 %22, 8
%24 = load i32, i32* %8
%25 = add nsw i32 %24, %23
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = call i32 (i8*, ...) @rcc_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load i8*, i8** %5
%29 = call i32 (i8*, ...) @rcc_printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %21
%33 = load i32, i32* %7
%34 = call i32 (i8*, ...) @rcc_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %32, %21
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 16
%38 = call i32 (i8*, ...) @rcc_printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%40 = load i8*, i8** %4
%41 = call i8* @mk_var(i8* %39, i8* %40, i32 0)
store i8* %41, i8** %10
%42 = load i8*, i8** %10
%43 = call i32 (i8*, ...) @rcc_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %42)
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c" add pc, $%d\0A\00"
@.str.1 = [14 x i8] c".string \22%s\22\0A\00"
@.str.2 = [16 x i8] c".fill %d, 1, 0\0A\00"
@.str.3 = [19 x i8] c" sub r0, pc, $%d\0A\00"
@.str.4 = [16 x i8] c" str r0, [%s]\0A\00"
define void @emit_set_string(i8* %0, i8* %1, i32 %2) {
%4 = alloca [32 x i8]
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %5, 1
%7 = srem i32 %6, 4
%8 = icmp eq i32 %7, 0
%9 = sub nsw i32 4, %7
%10 = select i1 %8, i32 0, i32 %9
%11 = add i32 %5, -7
%12 = add i32 %11, %10
%13 = tail call i32 (i8*, ...) @rcc_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = tail call i32 (i8*, ...) @rcc_printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%15 = icmp eq i32 %10, 0
br i1 %15, label %18, label %16
16: ; preds = %3
%17 = tail call i32 (i8*, ...) @rcc_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %18
18: ; preds = %16, %3
%19 = add nsw i32 %12, 16
%20 = tail call i32 (i8*, ...) @rcc_printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%22 = call i8* @mk_var(i8* %21, i8* %0, i32 0)
%23 = call i32 (i8*, ...) @rcc_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %22)
ret void
}