#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncat(char *, char *, int);
void print_formats(char **formats, char *dest, int limit) {
  int i = 0;
  memset(dest, 0, limit);
  while (formats[i] != NULL) {
    strncat(dest, "FORMAT=", limit);
    strncat(dest, formats[i++], limit);
  }
}


x86 assembly (clang, -O0):
<print_formats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1195 <print_formats+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe97(%rip),%rsi
call   1040 <strncat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x14(%rbp),%edx
call   1040 <strncat@plt>
jmp    1148 <print_formats+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_formats>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsi,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
cmpq   $0x0,0x0(%rbp)
je     1178 <print_formats+0x58>
add    $0x8,%rbp
lea    0xeb4(%rip),%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <strncat@plt>
mov    -0x8(%rbp),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1040 <strncat@plt>
cmpq   $0x0,0x0(%rbp)
lea    0x8(%rbp),%rbp
jne    1150 <print_formats+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"FORMAT=\00"
define void @print_formats(i8** %0, i8* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%8 = load i8*, i8** %5
%9 = load i32, i32* %6
%10 = call i32 @memset(i8* %8, i32 0, i32 %9)
br label %11
11: ; preds = %18, %3
%12 = load i8**, i8*** %4
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8*, i8** %12, i64 %14
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %31
18: ; preds = %11
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = call i32 @strncat(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i8*, i8** %5
%23 = load i8**, i8*** %4
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8*, i8** %23, i64 %26
%28 = load i8*, i8** %27
%29 = load i32, i32* %6
%30 = call i32 @strncat(i8* %22, i8* %28, i32 %29)
br label %11
31: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"FORMAT=\00"
define void @print_formats(i8** nocapture %0, i8* %1, i32 %2) {
%4 = tail call i32 @memset(i8* %1, i32 0, i32 %2)
%5 = load i8*, i8** %0
%6 = icmp eq i8* %5, null
br i1 %6, label %17, label %7
7: ; preds = %3, %7
%8 = phi i64 [ %11, %7 ], [ 0, %3 ]
%9 = phi i8** [ %14, %7 ], [ %0, %3 ]
%10 = tail call i32 @strncat(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %2)
%11 = add nuw i64 %8, 1
%12 = load i8*, i8** %9
%13 = tail call i32 @strncat(i8* %1, i8* %12, i32 %2)
%14 = getelementptr inbounds i8*, i8** %0, i64 %11
%15 = load i8*, i8** %14
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %7
17: ; preds = %7, %3
ret void
}