#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*/ EXIT_FAILURE;
int O_APPEND;
int O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ write(int, ...);
void insert(char *source, char *cible) {
  int descSource = open(source, O_RDONLY);
  int descCible = open(cible, O_WRONLY | O_APPEND);
  if (descCible == -1) {
    perror("Erreur d'ouverture du cible: ");
    exit(EXIT_FAILURE);
  } else if (descSource == -1) {
    perror("Erreur d'ouverture du source: ");
    exit(EXIT_FAILURE);
  }
  char buffer[2048];
  int nbLus = 0;
  int nbTotalLus = 0;
  while (nbLus = read(descSource, buffer, 2048)) {
    write(descCible, buffer, nbLus);
    nbTotalLus += nbLus;
  }
  printf("La taille du fichier à cacher est de %i\n", nbTotalLus);
  write(descCible, &nbTotalLus, sizeof(int));
  printf("Fichier %s inseré dans fichier %s !\n", source, cible);
}


x86 assembly (clang, -O0):
<insert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
mov    0x2e24(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11ca <insert+0x6a>
lea    0xe49(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11ee <insert+0x8e>
lea    0xe43(%rip),%rdi
call   1070 <perror@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11f3 <insert+0x93>
movl   $0x0,-0x824(%rbp)
movl   $0x0,-0x828(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x800,%edx
call   1050 <read@plt>
mov    %eax,-0x824(%rbp)
cmp    $0x0,%eax
je     1258 <insert+0xf8>
mov    -0x18(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0x824(%rbp),%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x824(%rbp),%eax
add    -0x828(%rbp),%eax
mov    %eax,-0x828(%rbp)
jmp    1207 <insert+0xa7>
mov    -0x828(%rbp),%esi
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x828(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%r13d
mov    0x2e39(%rip),%rax
mov    0x2e2a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     126e <insert+0x10e>
cmp    $0xffffffff,%r13d
je     1277 <insert+0x117>
mov    %eax,%r12d
mov    %rbx,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0x10(%rsp),%rsi
mov    %r13d,%edi
mov    $0x800,%edx
call   1050 <read@plt>
test   %eax,%eax
je     1220 <insert+0xc0>
mov    %eax,%r14d
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <write@plt>
add    %r14d,%ebp
mov    %ebp,0x4(%rsp)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1050 <read@plt>
mov    %eax,%r14d
test   %eax,%eax
jne    11f0 <insert+0x90>
jmp    1222 <insert+0xc2>
xor    %ebp,%ebp
lea    0xe14(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
mov    %r12d,%edi
xor    %eax,%eax
call   1030 <write@plt>
lea    0xe1a(%rip),%rdi
mov    %r15,%rsi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd8b(%rip),%rdi
jmp    127e <insert+0x11e>
lea    0xda0(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@.str = [30 x i8] c"Erreur d'ouverture du cible: \00"
@EXIT_FAILURE = global i32 0
@.str.1 = [31 x i8] c"Erreur d'ouverture du source: \00"
@.str.2 = [42 x i8] c"La taille du fichier \C3\A0 cacher est de %i\0A\00"
@.str.3 = [38 x i8] c"Fichier %s inser\C3\A9 dans fichier %s !\0A\00"
define void @insert(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2048 x i8]
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %5
%13 = load i8*, i8** %4
%14 = load i32, i32* @O_WRONLY
%15 = load i32, i32* @O_APPEND
%16 = or i32 %14, %15
%17 = call i32 @open(i8* %13, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
%25 = load i32, i32* %5
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %24
br label %32
32: ; preds = %31
store i32 0, i32* %8
store i32 0, i32* %9
br label %33
33: ; preds = %38, %32
%34 = load i32, i32* %5
%35 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%36 = call i32 @read(i32 %34, i8* %35, i32 2048)
store i32 %36, i32* %8
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %33
%39 = load i32, i32* %6
%40 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%41 = load i32, i32* %8
%42 = call i32 (i32, ...) @write(i32 %39, i8* %40, i32 %41)
%43 = load i32, i32* %8
%44 = load i32, i32* %9
%45 = add nsw i32 %44, %43
store i32 %45, i32* %9
br label %33
46: ; preds = %33
%47 = load i32, i32* %9
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %6
%50 = call i32 (i32, ...) @write(i32 %49, i32* %9, i64 4)
%51 = load i8*, i8** %3
%52 = load i8*, i8** %4
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %51, i8* %52)
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@.str = [30 x i8] c"Erreur d'ouverture du cible: \00"
@EXIT_FAILURE = global i32 0
@.str.1 = [31 x i8] c"Erreur d'ouverture du source: \00"
@.str.2 = [42 x i8] c"La taille du fichier \C3\A0 cacher est de %i\0A\00"
@.str.3 = [38 x i8] c"Fichier %s inser\C3\A9 dans fichier %s !\0A\00"
define void @insert(i8* %0, i8* %1) {
%3 = alloca [2048 x i8]
%4 = alloca i32
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_APPEND
%9 = or i32 %8, %7
%10 = tail call i32 @open(i8* %1, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = icmp eq i32 %6, -1
br i1 %17, label %18, label %22
18: ; preds = %16
%19 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %16
%23 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%24 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%25 = call i32 @read(i32 %6, i8* %23, i32 2048)
%26 = icmp eq i32 %25, 0
br i1 %26, label %34, label %27
27: ; preds = %22, %27
%28 = phi i32 [ %31, %27 ], [ 0, %22 ]
%29 = phi i32 [ %32, %27 ], [ %25, %22 ]
%30 = call i32 (i32, ...) @write(i32 %10, i8* %23, i32 %29)
%31 = add nsw i32 %28, %29
store i32 %31, i32* %4
%32 = call i32 @read(i32 %6, i8* %23, i32 2048)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %27
34: ; preds = %27, %22
%35 = phi i32 [ 0, %22 ], [ %31, %27 ]
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = call i32 (i32, ...) @write(i32 %10, i32* %4, i64 4)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %1)
ret void
}