#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
size_t strlen(char *);
int creer_fichier(FILE *f1, FILE *f2, int nb) {
  char buf[100 + 1];
  int n = 0;
  while (fgets(buf, 100, f1) != NULL && n <= nb) {
    fputs(buf, f2);
    if (buf[strlen(buf) - 1] == '\n')
      fputs(" ", f2);
    n = n + buf[strlen(buf)];
  }
  return 0;
}


x86 assembly (clang, -O0):
<creer_fichier>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x84(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x85(%rbp)
je     1189 <creer_fichier+0x59>
mov    -0x84(%rbp),%eax
cmp    -0x14(%rbp),%eax
setle  %al
mov    %al,-0x85(%rbp)
mov    -0x85(%rbp),%al
test   $0x1,%al
jne    119c <creer_fichier+0x6c>
jmp    1204 <creer_fichier+0xd4>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <fputs@plt>
lea    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    11d4 <creer_fichier+0xa4>
mov    -0x10(%rbp),%rsi
lea    0xe31(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x84(%rbp),%eax
mov    %eax,-0x8c(%rbp)
lea    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x8c(%rbp),%eax
movsbl -0x80(%rbp,%rcx,1),%ecx
add    %ecx,%eax
mov    %eax,-0x84(%rbp)
jmp    1150 <creer_fichier+0x20>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<creer_fichier>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsp,%r13
mov    %r13,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11d0 <creer_fichier+0x90>
test   %r14d,%r14d
js     11d0 <creer_fichier+0x90>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
mov    %r13,%rdi
call   1030 <strlen@plt>
cmpb   $0xa,-0x1(%rax,%r13,1)
jne    11a8 <creer_fichier+0x68>
mov    $0x20,%edi
mov    %r12,%rsi
call   1050 <fputc@plt>
mov    %r13,%rdi
call   1030 <strlen@plt>
movsbl (%rsp,%rax,1),%ebp
mov    %r13,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11d0 <creer_fichier+0x90>
add    %ebp,%ebx
cmp    %r14d,%ebx
jle    1180 <creer_fichier+0x40>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i32 @creer_fichier(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [101 x i8]
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %8
br label %9
9: ; preds = %34, %3
%10 = getelementptr inbounds [101 x i8], [101 x i8]* %7, i64 0, i64 0
%11 = load i32*, i32** %4
%12 = call i32* @fgets(i8* %10, i32 100, i32* %11)
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* %8
%16 = load i32, i32* %6
%17 = icmp sle i32 %15, %16
br label %18
18: ; preds = %14, %9
%19 = phi i1 [ false, %9 ], [ %17, %14 ]
br i1 %19, label %20, label %42
20: ; preds = %18
%21 = getelementptr inbounds [101 x i8], [101 x i8]* %7, i64 0, i64 0
%22 = load i32*, i32** %5
%23 = call i32 @fputs(i8* %21, i32* %22)
%24 = getelementptr inbounds [101 x i8], [101 x i8]* %7, i64 0, i64 0
%25 = call i64 @strlen(i8* %24)
%26 = sub i64 %25, 1
%27 = getelementptr inbounds [101 x i8], [101 x i8]* %7, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 10
br i1 %30, label %31, label %34
31: ; preds = %20
%32 = load i32*, i32** %5
%33 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32* %32)
br label %34
34: ; preds = %31, %20
%35 = load i32, i32* %8
%36 = getelementptr inbounds [101 x i8], [101 x i8]* %7, i64 0, i64 0
%37 = call i64 @strlen(i8* %36)
%38 = getelementptr inbounds [101 x i8], [101 x i8]* %7, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = add nsw i32 %35, %40
store i32 %41, i32* %8
br label %9
42: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
define i32 @creer_fichier(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = alloca [101 x i8]
%5 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%6 = call i32* @fgets(i8* %5, i32 100, i32* %0)
%7 = icmp ne i32* %6, null
%8 = icmp sgt i32 %2, -1
%9 = and i1 %7, %8
br i1 %9, label %10, label %30
10: ; preds = %3, %20
%11 = phi i32 [ %25, %20 ], [ 0, %3 ]
%12 = call i32 @fputs(i8* %5, i32* %1)
%13 = call i64 @strlen(i8* %5)
%14 = add i64 %13, -1
%15 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 10
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = call i32 @fputc(i32 32, i32* %1)
br label %20
20: ; preds = %18, %10
%21 = call i64 @strlen(i8* %5)
%22 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = add nsw i32 %11, %24
%26 = call i32* @fgets(i8* %5, i32 100, i32* %0)
%27 = icmp ne i32* %26, null
%28 = icmp sle i32 %25, %2
%29 = select i1 %27, i1 %28, i1 false
br i1 %29, label %10, label %30
30: ; preds = %20, %3
ret i32 0
}