#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*/ *const, char *, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *const);
void write_commands(FILE *const fp, char *cmds_list[], char *cmds[],
                    int ncmds) {
  int i;
  fputs("\n# Commands:\n", fp);
  for (i = 0; cmds_list[i] != NULL; i += 2) {
    fprintf(fp, "!%s\n\t%s\n", cmds_list[i], cmds_list[i + 1]);
  }
  for (i = 0; i < ncmds; i += 2) {
    fprintf(fp, "!%s\n\t%s\n", cmds[i], cmds[i + 1]);
  }
}


x86 assembly (clang, -O0):
<write_commands>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xebe(%rip),%rdi
call   1030 <fputs@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     119c <write_commands+0x7c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe85(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    114e <write_commands+0x2e>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ea <write_commands+0xca>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe37(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    11a3 <write_commands+0x83>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_commands>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xec5(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1040 <fwrite@plt>
mov    (%rbx),%rdx
test   %rdx,%rdx
je     117b <write_commands+0x5b>
add    $0x10,%rbx
lea    0xeae(%rip),%r12
mov    -0x8(%rbx),%rcx
mov    %rbp,%rdi
mov    %r12,%rsi
call   1030 <fprintf@plt>
mov    (%rbx),%rdx
add    $0x10,%rbx
test   %rdx,%rdx
jne    1160 <write_commands+0x40>
test   %r14d,%r14d
jle    11ad <write_commands+0x8d>
xor    %ebx,%ebx
lea    0xe85(%rip),%r12
nopl   0x0(%rax)
mov    (%r15,%rbx,8),%rdx
mov    0x8(%r15,%rbx,8),%rcx
mov    %rbp,%rdi
mov    %r12,%rsi
call   1030 <fprintf@plt>
add    $0x2,%rbx
cmp    %r14d,%ebx
jl     1190 <write_commands+0x70>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"\0A# Commands:\0A\00"
@.str.1 = [9 x i8] c"!%s\0A\09%s\0A\00"
define void @write_commands(i32* %0, i8** %1, i8** %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 %3, i32* %8
%10 = load i32*, i32** %5
%11 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* %10)
store i32 0, i32* %9
br label %12
12: ; preds = %33, %4
%13 = load i8**, i8*** %6
%14 = load i32, i32* %9
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %36
19: ; preds = %12
%20 = load i32*, i32** %5
%21 = load i8**, i8*** %6
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %6
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %26, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* %31)
br label %33
33: ; preds = %19
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 2
store i32 %35, i32* %9
br label %12
36: ; preds = %12
store i32 0, i32* %9
br label %37
37: ; preds = %55, %36
%38 = load i32, i32* %9
%39 = load i32, i32* %8
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %58
41: ; preds = %37
%42 = load i32*, i32** %5
%43 = load i8**, i8*** %7
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = load i8**, i8*** %7
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %48, i64 %51
%53 = load i8*, i8** %52
%54 = call i32 @fprintf(i32* %42, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %47, i8* %53)
br label %55
55: ; preds = %41
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 2
store i32 %57, i32* %9
br label %37
58: ; preds = %37
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"\0A# Commands:\0A\00"
@.str.1 = [9 x i8] c"!%s\0A\09%s\0A\00"
define void @write_commands(i32* nocapture %0, i8** nocapture %1, i8** nocapture %2, i32 %3) {
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 13, i64 1, i32* %0)
%6 = load i8*, i8** %1
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %10, %4
%9 = icmp sgt i32 %3, 0
br i1 %9, label %21, label %32
10: ; preds = %4, %10
%11 = phi i64 [ %17, %10 ], [ 0, %4 ]
%12 = phi i8* [ %19, %10 ], [ %6, %4 ]
%13 = or i64 %11, 1
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %15)
%17 = add nuw i64 %11, 2
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %8, label %10
21: ; preds = %8, %21
%22 = phi i64 [ %29, %21 ], [ 0, %8 ]
%23 = getelementptr inbounds i8*, i8** %2, i64 %22
%24 = load i8*, i8** %23
%25 = or i64 %22, 1
%26 = getelementptr inbounds i8*, i8** %2, i64 %25
%27 = load i8*, i8** %26
%28 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* %27)
%29 = add nuw i64 %22, 2
%30 = trunc i64 %29 to i32
%31 = icmp slt i32 %30, %3
br i1 %31, label %21, label %32
32: ; preds = %21, %8
ret void
}