#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 */
int /*<<< orphan*/ str_add_char(char *, int, char);
int strlen(char *);
void str_add(char *S, char *ADD, int n) {
  int add_len = strlen(ADD);
  for (int i = add_len - 1; i >= 0; i--) {
    str_add_char(S, n, ADD[i]);
  }
}


x86 assembly (clang, -O0):
<str_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1178 <str_add+0x58>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
call   1040 <str_add_char@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1148 <str_add+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_add>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    116c <str_add+0x4c>
mov    %eax,%ebp
add    $0x1,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    -0x2(%rbp),%eax
movsbl (%rbx,%rax,1),%edx
mov    %r15,%rdi
mov    %r14d,%esi
call   1040 <str_add_char@plt>
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%rbp
ja     1150 <str_add+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @str_add(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = sub nsw i32 %11, 1
store i32 %12, i32* %8
br label %13
13: ; preds = %25, %3
%14 = load i32, i32* %8
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %13
%17 = load i8*, i8** %4
%18 = load i32, i32* %6
%19 = load i8*, i8** %5
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = call i32 @str_add_char(i8* %17, i32 %18, i8 signext %23)
br label %25
25: ; preds = %16
%26 = load i32, i32* %8
%27 = add nsw i32 %26, -1
store i32 %27, i32* %8
br label %13
28: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @str_add(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = zext i32 %4 to i64
br label %9
8: ; preds = %9, %3
ret void
9: ; preds = %6, %9
%10 = phi i64 [ %7, %6 ], [ %11, %9 ]
%11 = add nsw i64 %10, -1
%12 = and i64 %11, 4294967295
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = load i8, i8* %13
%15 = tail call i32 @str_add_char(i8* %0, i32 %2, i8 signext %14)
%16 = icmp ugt i64 %10, 1
br i1 %16, label %9, label %8
}