#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ mygetline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int strlen(char *);
int main(int argc, char *argv[]) {
  char *linebuf = NULL;
  size_t linesize = 0;
  FILE *fp;
  if (argc < 2) {
    fprintf(stderr, "Usage:%s <srcfile> <destfile>\n", argv[0]);
    exit(1);
  }
  fp = fopen(argv[1], "r");
  if (fp = NULL) {
    perror("fopen()");
    exit(1);
  }
  while (1) {
    if (mygetline(&linebuf, &linesize, fp) < 0)
      break;
    printf("linesize = %d\n", linesize);
    printf("%d\n", strlen(linebuf));
  }
  fclose(fp);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d6 <main+0x56>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x28(%rbp)
xor    %eax,%eax
test   $0x1,%al
jne    1205 <main+0x85>
jmp    121b <main+0x9b>
lea    0xe15(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1220 <main+0xa0>
mov    -0x28(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <mygetline@plt>
cmp    $0x0,%rax
jge    1240 <main+0xc0>
jmp    126e <main+0xee>
mov    -0x20(%rbp),%rax
mov    %eax,%esi
lea    0xddc(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
lea    0xdd0(%rip),%rdi
call   1050 <printf@plt>
jmp    1220 <main+0xa0>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
cmp    $0x1,%edi
jg     11b4 <main+0x44>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe5b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x8(%rsi),%rdi
lea    0xe60(%rip),%rsi
call   1080 <fopen@plt>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1070 <mygetline@plt>
test   %rax,%rax
js     1232 <main+0xc2>
lea    0xe40(%rip),%r14
lea    0xe44(%rip),%r15
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x8(%rsp),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x10(%rsp),%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1070 <mygetline@plt>
test   %rax,%rax
jns    1200 <main+0x90>
xor    %edi,%edi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Usage:%s <srcfile> <destfile>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"fopen()\00"
@.str.3 = [15 x i8] c"linesize = %d\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i64 0, i64* %7
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %8
store i32* null, i32** %8
br i1 false, label %23, label %26
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %18
br label %27
27: ; preds = %26, %32
%28 = load i32*, i32** %8
%29 = call i64 @mygetline(i8** %6, i64* %7, i32* %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
br label %39
32: ; preds = %27
%33 = load i64, i64* %7
%34 = trunc i64 %33 to i32
%35 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = load i8*, i8** %6
%37 = call i32 @strlen(i8* %36)
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %37)
br label %27
39: ; preds = %31
%40 = load i32*, i32** %8
%41 = call i32 @fclose(i32* %40)
%42 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Usage:%s <srcfile> <destfile>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [15 x i8] c"linesize = %d\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = call i64 @mygetline(i8** %3, i64* %4, i32* null)
%18 = icmp slt i64 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %13, %19
%20 = load i64, i64* %4
%21 = trunc i64 %20 to i32
%22 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%26 = call i64 @mygetline(i8** %3, i64* %4, i32* null)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %19
28: ; preds = %19, %13
%29 = call i32 @fclose(i32* null)
%30 = call i32 @exit(i32 0)
unreachable
}