#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*/ bzero(char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ xmalloc(int);
int writeln(FILE *in1_fd, FILE *out_fd, int n) {
  int i = 0;
  char *buf;
  buf = (char *)xmalloc(200);
  for (; i < n; i++) {
    if (fgets(buf, 200, in1_fd) == NULL) {
      exit(errno);
    }
    fprintf(out_fd, "%s", buf);
    bzero(buf, 200);
  }
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<writeln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0xc8,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ee <writeln+0x8e>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0xc8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    11be <writeln+0x5e>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe33(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    $0xc8,%esi
call   1070 <bzero@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1188 <writeln+0x28>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeln>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0xc8,%edi
call   1050 <xmalloc@plt>
mov    %rax,%r12
test   %ebx,%ebx
jle    11c2 <writeln+0x62>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0xc8,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11d8 <writeln+0x78>
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
mov    %r12,%rdi
mov    $0xc8,%esi
call   1070 <bzero@plt>
add    $0xffffffff,%ebx
jne    1190 <writeln+0x30>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @writeln(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%9 = call i64 @xmalloc(i32 200)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %8
br label %11
11: ; preds = %29, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %32
15: ; preds = %11
%16 = load i8*, i8** %8
%17 = load i32*, i32** %4
%18 = call i32* @fgets(i8* %16, i32 200, i32* %17)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i32, i32* @errno
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %15
%24 = load i32*, i32** %5
%25 = load i8*, i8** %8
%26 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %8
%28 = call i32 @bzero(i8* %27, i32 200)
br label %29
29: ; preds = %23
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %11
32: ; preds = %11
%33 = load i8*, i8** %8
%34 = call i32 @free(i8* %33)
ret i32 0
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @writeln(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = tail call i64 @xmalloc(i32 200)
%5 = inttoptr i64 %4 to i8*
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %19
7: ; preds = %3, %14
%8 = phi i32 [ %17, %14 ], [ 0, %3 ]
%9 = tail call i32* @fgets(i8* %5, i32 200, i32* %0)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* @errno
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %7
%15 = tail call i32 @fputs(i8* %5, i32* %1)
%16 = tail call i32 @bzero(i8* %5, i32 200)
%17 = add nuw nsw i32 %8, 1
%18 = icmp eq i32 %17, %2
br i1 %18, label %19, label %7
19: ; preds = %14, %3
%20 = tail call i32 @free(i8* %5)
ret i32 0
}