#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*/ fcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, long);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int sscanf(char const *, char *, long *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
scalar_t__ strlen(char *);
long copy_data(FILE *to, FILE *from, const char *line) {
  long count, amount = 0;
  char str[258];
  str[0] = '\0';
  if (sscanf(line + 12, "%ld %*s %s", &count, str) >= 1) {
    if (!strcmp(str, "Lines"))
      for (; count > 0; --count) {
        if (!fgets(str, 258, from))
          break;
        amount += strlen(str);
        if (to != NULL)
          fputs(str, to);
      }
    else {
      amount = count;
      fcpy(to, from, count);
    }
  }
  return amount;
}


x86 assembly (clang, -O0):
<copy_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movb   $0x0,-0x130(%rbp)
mov    -0x18(%rbp),%rdi
add    $0xc,%rdi
lea    -0x130(%rbp),%rcx
lea    0xe64(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jl     1265 <copy_data+0x105>
lea    -0x130(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1247 <copy_data+0xe7>
jmp    11cf <copy_data+0x6f>
cmpq   $0x0,-0x20(%rbp)
jle    1242 <copy_data+0xe2>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x102,%esi
call   1060 <fgets@plt>
cmp    $0x0,%eax
jne    11fd <copy_data+0x9d>
jmp    1242 <copy_data+0xe2>
lea    -0x130(%rbp),%rdi
call   1040 <strlen@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     122c <copy_data+0xcc>
lea    -0x130(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <fputs@plt>
jmp    1231 <copy_data+0xd1>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11cf <copy_data+0x6f>
jmp    1260 <copy_data+0x100>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <fcpy@plt>
jmp    1265 <copy_data+0x105>
mov    -0x28(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_data>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x120,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movb   $0x0,0x10(%rsp)
lea    0xc(%rdx),%rdi
lea    0xe8a(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1070 <sscanf@plt>
test   %eax,%eax
jle    1218 <copy_data+0xc8>
mov    $0x656e694c,%eax
xor    0x10(%rsp),%eax
movzwl 0x14(%rsp),%ecx
xor    $0x73,%ecx
or     %eax,%ecx
mov    0x8(%rsp),%rbx
je     11b7 <copy_data+0x67>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <fcpy@plt>
jmp    121a <copy_data+0xca>
test   %rbx,%rbx
jle    1218 <copy_data+0xc8>
xor    %ebx,%ebx
lea    0x10(%rsp),%r12
jmp    11e7 <copy_data+0x97>
cs nopw 0x0(%rax,%rax,1)
nop
add    %r13,%rbx
mov    0x8(%rsp),%rax
lea    -0x1(%rax),%rcx
mov    %rcx,0x8(%rsp)
cmp    $0x1,%rax
jle    121a <copy_data+0xca>
mov    %r12,%rdi
mov    $0x102,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %eax,%eax
je     121a <copy_data+0xca>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
test   %r15,%r15
je     11d0 <copy_data+0x80>
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <fputs@plt>
jmp    11d0 <copy_data+0x80>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x120,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%ld %*s %s\00"
@.str.1 = [6 x i8] c"Lines\00"
define i64 @copy_data(i32* %0, i32* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca [258 x i8]
store i32* %0, i32** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
store i64 0, i64* %8
%10 = getelementptr inbounds [258 x i8], [258 x i8]* %9, i64 0, i64 0
store i8 0, i8* %10
%11 = load i8*, i8** %6
%12 = getelementptr inbounds i8, i8* %11, i64 12
%13 = getelementptr inbounds [258 x i8], [258 x i8]* %9, i64 0, i64 0
%14 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64* %7, i8* %13)
%15 = icmp sge i32 %14, 1
br i1 %15, label %16, label %53
16: ; preds = %3
%17 = getelementptr inbounds [258 x i8], [258 x i8]* %9, i64 0, i64 0
%18 = call i32 @strcmp(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %46, label %20
20: ; preds = %16
br label %21
21: ; preds = %42, %20
%22 = load i64, i64* %7
%23 = icmp sgt i64 %22, 0
br i1 %23, label %24, label %45
24: ; preds = %21
%25 = getelementptr inbounds [258 x i8], [258 x i8]* %9, i64 0, i64 0
%26 = load i32*, i32** %5
%27 = call i32 @fgets(i8* %25, i32 258, i32* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %24
br label %45
30: ; preds = %24
%31 = getelementptr inbounds [258 x i8], [258 x i8]* %9, i64 0, i64 0
%32 = call i64 @strlen(i8* %31)
%33 = load i64, i64* %8
%34 = add nsw i64 %33, %32
store i64 %34, i64* %8
%35 = load i32*, i32** %4
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %41
37: ; preds = %30
%38 = getelementptr inbounds [258 x i8], [258 x i8]* %9, i64 0, i64 0
%39 = load i32*, i32** %4
%40 = call i32 @fputs(i8* %38, i32* %39)
br label %41
41: ; preds = %37, %30
br label %42
42: ; preds = %41
%43 = load i64, i64* %7
%44 = add nsw i64 %43, -1
store i64 %44, i64* %7
br label %21
45: ; preds = %29, %21
br label %52
46: ; preds = %16
%47 = load i64, i64* %7
store i64 %47, i64* %8
%48 = load i32*, i32** %4
%49 = load i32*, i32** %5
%50 = load i64, i64* %7
%51 = call i32 @fcpy(i32* %48, i32* %49, i64 %50)
br label %52
52: ; preds = %46, %45
br label %53
53: ; preds = %52, %3
%54 = load i64, i64* %8
ret i64 %54
}

LLVM IR (-O2):
@.str = [11 x i8] c"%ld %*s %s\00"
@.str.1 = [6 x i8] c"Lines\00"
define i64 @copy_data(i32* %0, i32* %1, i8* nocapture %2) {
%4 = alloca i64
%5 = alloca [258 x i8]
%6 = bitcast i64* %4 to i8*
%7 = getelementptr inbounds [258 x i8], [258 x i8]* %5, i64 0, i64 0
store i8 0, i8* %7
%8 = getelementptr inbounds i8, i8* %2, i64 12
%9 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64* %4, i8* %7)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %34
11: ; preds = %3
%12 = call i32 @bcmp(i8* dereferenceable(6) %7, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 6)
%13 = icmp eq i32 %12, 0
%14 = load i64, i64* %4
br i1 %13, label %15, label %32
15: ; preds = %11
%16 = icmp sgt i64 %14, 0
br i1 %16, label %17, label %34
17: ; preds = %15
%18 = icmp eq i32* %0, null
br label %19
19: ; preds = %17, %28
%20 = phi i64 [ 0, %17 ], [ %25, %28 ]
%21 = call i32 @fgets(i8* %7, i32 258, i32* %1)
%22 = icmp eq i32 %21, 0
br i1 %22, label %34, label %23
23: ; preds = %19
%24 = call i64 @strlen(i8* %7)
%25 = add nsw i64 %24, %20
br i1 %18, label %28, label %26
26: ; preds = %23
%27 = call i32 @fputs(i8* %7, i32* %0)
br label %28
28: ; preds = %23, %26
%29 = load i64, i64* %4
%30 = add nsw i64 %29, -1
store i64 %30, i64* %4
%31 = icmp sgt i64 %29, 1
br i1 %31, label %19, label %34
32: ; preds = %11
%33 = call i32 @fcpy(i32* %0, i32* %1, i64 %14)
br label %34
34: ; preds = %28, %19, %15, %32, %3
%35 = phi i64 [ %14, %32 ], [ 0, %3 ], [ 0, %15 ], [ %25, %28 ], [ %20, %19 ]
ret i64 %35
}