#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 ft_atoi(char *);
int /*<<< orphan*/ ft_printf(char *, ...);
int /*<<< orphan*/ ft_printf_fd(int, char *, ...);
int main(int ac, char **av) {
  int i;
  int fd;
  if (ac < 3) {
    ft_printf("usage: ./demo <target fd> <string1> … <string n>\n");
    return 1;
  }
  i = 2;
  fd = ft_atoi(av[1]);
  while (i < ac) {
    ft_printf_fd(fd, "arg no %d: %s\n", i, av[i]);
    i++;
  }
  ft_printf_fd(fd, "\n\033[33mMultistring test:\033[0m\n%s\n%s\n%c%s\n",
               "Standard commands:\n", "Digest commands:\n\tmd5\n\tsha256",
               '\n', "Cipher commands\n");
  ft_printf("ft_printf oddities [apparent but handled mismatches]\n\t- "
            "hex(Oxa1) for base10 int: %d\n",
            0xa1);
  ft_printf_fd(fd,
               "ft_printf_fd oddities [apparent but handled mismatches]\n\t- "
               "hex(Oxa1) for base10 int: %d\n",
               0xa1);
  ft_printf("\n\033[34mft_printf usage tests\033[0m\n");
  ft_printf("ft_printf tricky test [more arguments than tags]\n\t%s\n",
            "First argument", "Ignored argument");
  ft_printf("ft_printf tricky test [arguments but no tags]\n",
            "Undue argument");
  ft_printf("\n\033[34mft_printf_fd usage tests\033[0m\n");
  ft_printf_fd(fd,
               "ft_printf_fd tricky test [more arguments than tags]\n\t%s\n",
               "First argument", "Ignored argument");
  ft_printf_fd(fd, "ft_printf_fd tricky test [arguments but no tags]\n",
               "Undue argument");
  ft_printf("\n\033[34mEnd of demo\033[0m\n\t\t***\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    116a <main+0x3a>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <ft_printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a9 <main+0x179>
movl   $0x2,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <ft_atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11bb <main+0x8b>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe8e(%rip),%rsi
mov    $0x0,%al
call   1030 <ft_printf_fd@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1181 <main+0x51>
mov    -0x18(%rbp),%edi
lea    0xe7e(%rip),%rsi
lea    0xe9f(%rip),%rdx
lea    0xeac(%rip),%rcx
mov    $0xa,%r8d
lea    0xebd(%rip),%r9
mov    $0x0,%al
call   1030 <ft_printf_fd@plt>
lea    0xec0(%rip),%rdi
mov    $0xa1,%esi
mov    $0x0,%al
call   1040 <ft_printf@plt>
mov    -0x18(%rbp),%edi
lea    0xf00(%rip),%rsi
mov    $0xa1,%edx
mov    $0x0,%al
call   1030 <ft_printf_fd@plt>
lea    0xf46(%rip),%rdi
mov    $0x0,%al
call   1040 <ft_printf@plt>
lea    0xf59(%rip),%rdi
lea    0xf88(%rip),%rsi
lea    0xf90(%rip),%rdx
mov    $0x0,%al
call   1040 <ft_printf@plt>
lea    0xf93(%rip),%rdi
lea    0xfbb(%rip),%rsi
mov    $0x0,%al
call   1040 <ft_printf@plt>
lea    0xfbc(%rip),%rdi
mov    $0x0,%al
call   1040 <ft_printf@plt>
mov    -0x18(%rbp),%edi
lea    0xfcf(%rip),%rsi
lea    0xf46(%rip),%rdx
lea    0xf4e(%rip),%rcx
mov    $0x0,%al
call   1030 <ft_printf_fd@plt>
mov    -0x18(%rbp),%edi
lea    0xfe9(%rip),%rsi
lea    0xf76(%rip),%rdx
mov    $0x0,%al
call   1030 <ft_printf_fd@plt>
lea    0x1006(%rip),%rdi
mov    $0x0,%al
call   1040 <ft_printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x3,%edi
jge    114e <main+0x1e>
mov    $0x1,%ebp
lea    0xeb7(%rip),%rdi
jmp    126b <main+0x13b>
mov    %rsi,%r12
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
call   1050 <ft_atoi@plt>
mov    %eax,%r14d
mov    %ebx,%ebp
mov    $0x2,%ebx
lea    0xec7(%rip),%r15
nopl   (%rax)
mov    (%r12,%rbx,8),%rcx
mov    %r14d,%edi
mov    %r15,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <ft_printf_fd@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <main+0x40>
lea    0xeb0(%rip),%rsi
lea    0xed1(%rip),%rdx
lea    0xede(%rip),%rcx
lea    0xef5(%rip),%r9
xor    %ebp,%ebp
mov    %r14d,%edi
mov    $0xa,%r8d
xor    %eax,%eax
call   1030 <ft_printf_fd@plt>
lea    0xeed(%rip),%rdi
mov    $0xa1,%esi
xor    %eax,%eax
call   1040 <ft_printf@plt>
lea    0xf30(%rip),%rsi
mov    %r14d,%edi
mov    $0xa1,%edx
xor    %eax,%eax
call   1030 <ft_printf_fd@plt>
lea    0xf73(%rip),%rdi
xor    %eax,%eax
call   1040 <ft_printf@plt>
lea    0xf86(%rip),%rdi
lea    0xfb5(%rip),%r12
lea    0xfbd(%rip),%r15
mov    %r12,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <ft_printf@plt>
lea    0xfba(%rip),%rdi
lea    0xfe2(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <ft_printf@plt>
lea    0xfe0(%rip),%rdi
xor    %eax,%eax
call   1040 <ft_printf@plt>
lea    0xff6(%rip),%rsi
mov    %r14d,%edi
mov    %r12,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1030 <ft_printf_fd@plt>
lea    0x1018(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <ft_printf_fd@plt>
lea    0x1036(%rip),%rdi
xor    %eax,%eax
call   1040 <ft_printf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [52 x i8] c"usage: ./demo <target fd> <string1> \E2\80\A6 <string n>\0A\00"
@.str.1 = [15 x i8] c"arg no %d: %s\0A\00"
@.str.2 = [40 x i8] c"\0A\1B[33mMultistring test:\1B[0m\0A%s\0A%s\0A%c%s\0A\00"
@.str.3 = [20 x i8] c"Standard commands:\0A\00"
@.str.4 = [30 x i8] c"Digest commands:\0A\09md5\0A\09sha256\00"
@.str.5 = [17 x i8] c"Cipher commands\0A\00"
@.str.6 = [86 x i8] c"ft_printf oddities [apparent but handled mismatches]\0A\09- hex(Oxa1) for base10 int: %d\0A\00"
@.str.7 = [89 x i8] c"ft_printf_fd oddities [apparent but handled mismatches]\0A\09- hex(Oxa1) for base10 int: %d\0A\00"
@.str.8 = [33 x i8] c"\0A\1B[34mft_printf usage tests\1B[0m\0A\00"
@.str.9 = [54 x i8] c"ft_printf tricky test [more arguments than tags]\0A\09%s\0A\00"
@.str.10 = [15 x i8] c"First argument\00"
@.str.11 = [17 x i8] c"Ignored argument\00"
@.str.12 = [47 x i8] c"ft_printf tricky test [arguments but no tags]\0A\00"
@.str.13 = [15 x i8] c"Undue argument\00"
@.str.14 = [36 x i8] c"\0A\1B[34mft_printf_fd usage tests\1B[0m\0A\00"
@.str.15 = [57 x i8] c"ft_printf_fd tricky test [more arguments than tags]\0A\09%s\0A\00"
@.str.16 = [50 x i8] c"ft_printf_fd tricky test [arguments but no tags]\0A\00"
@.str.17 = [29 x i8] c"\0A\1B[34mEnd of demo\1B[0m\0A\09\09***\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @ft_printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %47
12: ; preds = %2
store i32 2, i32* %6
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @ft_atoi(i8* %15)
store i32 %16, i32* %7
br label %17
17: ; preds = %21, %12
%18 = load i32, i32* %6
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %32
21: ; preds = %17
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = load i8**, i8*** %5
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 (i32, i8*, ...) @ft_printf_fd(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %23, i8* %28)
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %17
32: ; preds = %17
%33 = load i32, i32* %7
%34 = call i32 (i32, i8*, ...) @ft_printf_fd(i32 %33, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 (i8*, ...) @ft_printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.6, i64 0, i64 0), i32 161)
%36 = load i32, i32* %7
%37 = call i32 (i32, i8*, ...) @ft_printf_fd(i32 %36, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.7, i64 0, i64 0), i32 161)
%38 = call i32 (i8*, ...) @ft_printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%39 = call i32 (i8*, ...) @ft_printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
%40 = call i32 (i8*, ...) @ft_printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0))
%41 = call i32 (i8*, ...) @ft_printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.14, i64 0, i64 0))
%42 = load i32, i32* %7
%43 = call i32 (i32, i8*, ...) @ft_printf_fd(i32 %42, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
%44 = load i32, i32* %7
%45 = call i32 (i32, i8*, ...) @ft_printf_fd(i32 %44, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0))
%46 = call i32 (i8*, ...) @ft_printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.17, i64 0, i64 0))
store i32 0, i32* %3
br label %47
47: ; preds = %32, %10
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [52 x i8] c"usage: ./demo <target fd> <string1> \E2\80\A6 <string n>\0A\00"
@.str.1 = [15 x i8] c"arg no %d: %s\0A\00"
@.str.2 = [40 x i8] c"\0A\1B[33mMultistring test:\1B[0m\0A%s\0A%s\0A%c%s\0A\00"
@.str.3 = [20 x i8] c"Standard commands:\0A\00"
@.str.4 = [30 x i8] c"Digest commands:\0A\09md5\0A\09sha256\00"
@.str.5 = [17 x i8] c"Cipher commands\0A\00"
@.str.6 = [86 x i8] c"ft_printf oddities [apparent but handled mismatches]\0A\09- hex(Oxa1) for base10 int: %d\0A\00"
@.str.7 = [89 x i8] c"ft_printf_fd oddities [apparent but handled mismatches]\0A\09- hex(Oxa1) for base10 int: %d\0A\00"
@.str.8 = [33 x i8] c"\0A\1B[34mft_printf usage tests\1B[0m\0A\00"
@.str.9 = [54 x i8] c"ft_printf tricky test [more arguments than tags]\0A\09%s\0A\00"
@.str.10 = [15 x i8] c"First argument\00"
@.str.11 = [17 x i8] c"Ignored argument\00"
@.str.12 = [47 x i8] c"ft_printf tricky test [arguments but no tags]\0A\00"
@.str.13 = [15 x i8] c"Undue argument\00"
@.str.14 = [36 x i8] c"\0A\1B[34mft_printf_fd usage tests\1B[0m\0A\00"
@.str.15 = [57 x i8] c"ft_printf_fd tricky test [more arguments than tags]\0A\09%s\0A\00"
@.str.16 = [50 x i8] c"ft_printf_fd tricky test [arguments but no tags]\0A\00"
@.str.17 = [29 x i8] c"\0A\1B[34mEnd of demo\1B[0m\0A\09\09***\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %27, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @ft_atoi(i8* %6)
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %4, %9
%10 = phi i64 [ 2, %4 ], [ %15, %9 ]
%11 = getelementptr inbounds i8*, i8** %1, i64 %10
%12 = load i8*, i8** %11
%13 = trunc i64 %10 to i32
%14 = tail call i32 (i32, i8*, ...) @ft_printf_fd(i32 %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %13, i8* %12)
%15 = add nuw nsw i64 %10, 1
%16 = icmp eq i64 %15, %8
br i1 %16, label %17, label %9
17: ; preds = %9
%18 = tail call i32 (i32, i8*, ...) @ft_printf_fd(i32 %7, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%19 = tail call i32 (i8*, ...) @ft_printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.6, i64 0, i64 0), i32 161)
%20 = tail call i32 (i32, i8*, ...) @ft_printf_fd(i32 %7, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.7, i64 0, i64 0), i32 161)
%21 = tail call i32 (i8*, ...) @ft_printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%22 = tail call i32 (i8*, ...) @ft_printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
%23 = tail call i32 (i8*, ...) @ft_printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0))
%24 = tail call i32 (i8*, ...) @ft_printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.14, i64 0, i64 0))
%25 = tail call i32 (i32, i8*, ...) @ft_printf_fd(i32 %7, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
%26 = tail call i32 (i32, i8*, ...) @ft_printf_fd(i32 %7, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0))
br label %27
27: ; preds = %2, %17
%28 = phi i8* [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.17, i64 0, i64 0), %17 ], [ getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), %2 ]
%29 = phi i32 [ 0, %17 ], [ 1, %2 ]
%30 = tail call i32 (i8*, ...) @ft_printf(i8* %28)
ret i32 %29
}