#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *serializeVersionText(char *filename, int len, char *buf) {
  buf[0] = '\0';
  FILE *file;
  if ((file = fopen(filename, "r")) != NULL) {
    char line[100];
    while (fgets(line, 100, file) != NULL) {
      int l = strlen(line);
      if (len > l) {
        strcat(buf, line);
        len -= l;
      }
    }
    fclose(file);
    return (buf);
  }
  return (NULL);
}


x86 assembly (clang, -O0):
<serializeVersionText>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1209 <serializeVersionText+0xb9>
jmp    1190 <serializeVersionText+0x40>
lea    -0x90(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11f3 <serializeVersionText+0xa3>
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x94(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x94(%rbp),%eax
jle    11ee <serializeVersionText+0x9e>
mov    -0x20(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x94(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1190 <serializeVersionText+0x40>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1211 <serializeVersionText+0xc1>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serializeVersionText>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %rdx,%r14
mov    %esi,%r12d
movb   $0x0,(%rdx)
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11de <serializeVersionText+0x8e>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11d4 <serializeVersionText+0x84>
mov    %rsp,%rbx
jmp    11b5 <serializeVersionText+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11d4 <serializeVersionText+0x84>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r12d,%ebp
sub    %eax,%ebp
jle    11a0 <serializeVersionText+0x50>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <strcat@plt>
mov    %ebp,%r12d
jmp    11a0 <serializeVersionText+0x50>
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    11e1 <serializeVersionText+0x91>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i8* @serializeVersionText(i8* nocapture %0, i32 %1, i8* %2) {
%4 = alloca [100 x i8]
store i8 0, i8* %2
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %24, label %7
7: ; preds = %3
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = call i32* @fgets(i8* %8, i32 100, i32* %5)
%10 = icmp eq i32* %9, null
br i1 %10, label %22, label %11
11: ; preds = %7, %18
%12 = phi i32 [ %19, %18 ], [ %1, %7 ]
%13 = call i32 @strlen(i8* %8)
%14 = icmp sgt i32 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @strcat(i8* %2, i8* %8)
%17 = sub nsw i32 %12, %13
br label %18
18: ; preds = %15, %11
%19 = phi i32 [ %17, %15 ], [ %12, %11 ]
%20 = call i32* @fgets(i8* %8, i32 100, i32* %5)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %11
22: ; preds = %18, %7
%23 = call i32 @fclose(i32* %5)
br label %24
24: ; preds = %3, %22
%25 = phi i8* [ %2, %22 ], [ null, %3 ]
ret i8* %25
}