#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*/ free(char *);
char *ft_strdup(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int ac, char **av) {
  printf("-----------------------\n");
  printf("        strdup         \n");
  printf("-----------------------\n");
  char *str = NULL;
  printf("AVANT :\n");
  printf("adress = %p\n'%s'\n", str, str);
  str = ft_strdup(str);
  printf("APRES :\n");
  printf("adress = %p\n'%s'\n", str, str);
  free(str);
  printf("-----------------------\n");
  str = "abcdef";
  printf("AVANT :\n");
  printf("adress = %p\n'%s'\n", str, str);
  str = ft_strdup(str);
  printf("APRES :\n");
  printf("adress = %p\n'%s'\n", str, str);
  free(str);
  printf("-----------------------\n");
  str = "Un truc beaucoup beaucoup beaucoup plus long avec\ndes\nretours a "
        "\nla\nligne t\no\nut partout :)";
  printf("AVANT :\n");
  printf("adress = %p\n'%s'\n", str, str);
  str = ft_strdup(str);
  printf("APRES :\n");
  printf("adress = %p\n'%s'\n", str, str);
  free(str);
  printf("\n\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)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x18(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ft_strdup@plt>
mov    %rax,-0x18(%rbp)
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6b(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ft_strdup@plt>
mov    %rax,-0x18(%rbp)
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdfb(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ft_strdup@plt>
mov    %rax,-0x18(%rbp)
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xf3d(%rip),%r14
mov    %r14,%rdi
call   1040 <puts@plt>
lea    0xf16(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
lea    0xf32(%rip),%r15
mov    %r15,%rdi
call   1040 <puts@plt>
lea    0xe7e(%rip),%r13
mov    %r13,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <ft_strdup@plt>
mov    %rax,%rbx
lea    0xf0c(%rip),%r12
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
lea    0xe3a(%rip),%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <ft_strdup@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
lea    0xdef(%rip),%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <ft_strdup@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xda4(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"-----------------------\0A\00"
@.str.1 = [25 x i8] c" strdup \0A\00"
@.str.2 = [9 x i8] c"AVANT :\0A\00"
@.str.3 = [18 x i8] c"adress = %p\0A'%s'\0A\00"
@.str.4 = [9 x i8] c"APRES :\0A\00"
@.str.5 = [7 x i8] c"abcdef\00"
@.str.6 = [92 x i8] c"Un truc beaucoup beaucoup beaucoup plus long avec\0Ades\0Aretours a \0Ala\0Aligne t\0Ao\0Aut partout :)\00"
@.str.7 = [3 x i8] c"\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%11 = load i8*, i8** %6
%12 = load i8*, i8** %6
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %11, i8* %12)
%14 = load i8*, i8** %6
%15 = call i8* @ft_strdup(i8* %14)
store i8* %15, i8** %6
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%17 = load i8*, i8** %6
%18 = load i8*, i8** %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %17, i8* %18)
%20 = load i8*, i8** %6
%21 = call i32 @free(i8* %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8** %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%24 = load i8*, i8** %6
%25 = load i8*, i8** %6
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %24, i8* %25)
%27 = load i8*, i8** %6
%28 = call i8* @ft_strdup(i8* %27)
store i8* %28, i8** %6
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%30 = load i8*, i8** %6
%31 = load i8*, i8** %6
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %30, i8* %31)
%33 = load i8*, i8** %6
%34 = call i32 @free(i8* %33)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.6, i64 0, i64 0), i8** %6
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%37 = load i8*, i8** %6
%38 = load i8*, i8** %6
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %37, i8* %38)
%40 = load i8*, i8** %6
%41 = call i8* @ft_strdup(i8* %40)
store i8* %41, i8** %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%43 = load i8*, i8** %6
%44 = load i8*, i8** %6
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %43, i8* %44)
%46 = load i8*, i8** %6
%47 = call i32 @free(i8* %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [18 x i8] c"adress = %p\0A'%s'\0A\00"
@.str.5 = [7 x i8] c"abcdef\00"
@.str.6 = [92 x i8] c"Un truc beaucoup beaucoup beaucoup plus long avec\0Ades\0Aretours a \0Ala\0Aligne t\0Ao\0Aut partout :)\00"
@str.8 = [24 x i8] c" strdup \00"
@str.15 = [24 x i8] c"-----------------------\00"
@str.16 = [8 x i8] c"AVANT :\00"
@str.17 = [8 x i8] c"APRES :\00"
@str.18 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.15, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.8, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.15, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.16, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* null, i8* null)
%8 = tail call i8* @ft_strdup(i8* null)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.17, i64 0, i64 0))
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %8, i8* %8)
%11 = tail call i32 @free(i8* %8)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.15, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.16, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%15 = tail call i8* @ft_strdup(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.17, i64 0, i64 0))
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %15, i8* %15)
%18 = tail call i32 @free(i8* %15)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.15, i64 0, i64 0))
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.16, i64 0, i64 0))
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.6, i64 0, i64 0))
%22 = tail call i8* @ft_strdup(i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.6, i64 0, i64 0))
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.17, i64 0, i64 0))
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %22, i8* %22)
%25 = tail call i32 @free(i8* %22)
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.18, i64 0, i64 0))
ret i32 0
}