#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
char *my_malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int strlen(char *);
char *add_nvram_contents(char *url, char *folder) {
  printf("add_nvram_contents start\n");
  char *nv;
  int nv_len;
  char *new_nv;
  char *nvp;
  nvp = my_malloc(strlen(url) + strlen(folder) + 2);
  sprintf(nvp, "%s>%s", url, folder);
  printf("add_nvram_contents     nvp = %s\n", nvp);
  FILE *fp;
  fp = fopen("/opt/etc/smb_tokenfile", "r");
  if (fp == NULL) {
    nv = my_malloc(2);
    sprintf(nv, "");
  } else {
    fseek(fp, 0, SEEK_END);
    int file_size;
    file_size = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    nv = my_malloc(file_size + 2);
    fscanf(fp, "%[^\n]%*c", nv);
    fclose(fp);
  }
  printf("add_nvram_contents() - nv = %s\n", nv);
  nv_len = strlen(nv);
  if (nv_len) {
    new_nv = my_malloc(strlen(nv) + strlen(nvp) + 2);
    sprintf(new_nv, "%s<%s", nv, nvp);
  } else {
    new_nv = my_malloc(strlen(nvp) + 1);
    sprintf(new_nv, "%s", nvp);
  }
  free(nvp);
  free(nv);
  printf("add_nvram_contents end\n");
  return new_nv;
}


x86 assembly (clang, -O0):
<add_nvram_contents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x40(%rbp),%edi
add    %eax,%edi
add    $0x2,%edi
call   1040 <my_malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe2a(%rip),%rdi
lea    0xe3a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1257 <add_nvram_contents+0xb7>
mov    $0x2,%edi
call   1040 <my_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
jmp    12b7 <add_nvram_contents+0x117>
mov    -0x38(%rbp),%rdi
mov    0x2d86(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x38(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
mov    0x2d56(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x3c(%rbp),%edi
add    $0x2,%edi
call   1040 <my_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdb1(%rip),%rsi
call   1080 <fscanf@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rsi
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1324 <add_nvram_contents+0x184>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x44(%rbp),%edi
add    %eax,%edi
add    $0x2,%edi
call   1040 <my_malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xd6b(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
jmp    1351 <add_nvram_contents+0x1b1>
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1040 <my_malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xd3c(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_nvram_contents>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe9a(%rip),%rdi
call   1060 <puts@plt>
mov    %r12,%rdi
call   1080 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1080 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1040 <my_malloc@plt>
mov    %rax,%r14
lea    0xdff(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   10e0 <sprintf@plt>
lea    0xdee(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xdfe(%rip),%rdi
lea    0xe0e(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1296 <add_nvram_contents+0xd6>
mov    %rax,%rbx
mov    0x2da4(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %rbx,%rdi
call   10b0 <ftell@plt>
mov    %eax,%ebp
mov    0x2d77(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
add    $0x2,%ebp
mov    %ebp,%edi
call   1040 <my_malloc@plt>
mov    %rax,%r15
lea    0xdbf(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
call   10a0 <fscanf@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
jmp    12a6 <add_nvram_contents+0xe6>
mov    $0x2,%edi
call   1040 <my_malloc@plt>
mov    %rax,%r15
movb   $0x0,(%rax)
lea    0xd9c(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r15,%rdi
call   1080 <strlen@plt>
test   %eax,%eax
je     12fc <add_nvram_contents+0x13c>
mov    %r15,%rdi
call   1080 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1080 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1040 <my_malloc@plt>
mov    %rax,%rbx
lea    0xd7f(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   10e0 <sprintf@plt>
jmp    131a <add_nvram_contents+0x15a>
mov    %r14,%rdi
call   1080 <strlen@plt>
lea    0x1(%rax),%edi
call   1040 <my_malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xd57(%rip),%rdi
call   1060 <puts@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"add_nvram_contents start\0A\00"
@.str.1 = [6 x i8] c"%s>%s\00"
@.str.2 = [33 x i8] c"add_nvram_contents nvp = %s\0A\00"
@.str.3 = [23 x i8] c"/opt/etc/smb_tokenfile\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [1 x i8] zeroinitializer
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.6 = [9 x i8] c"%[^\0A]%*c\00"
@.str.7 = [32 x i8] c"add_nvram_contents() - nv = %s\0A\00"
@.str.8 = [6 x i8] c"%s<%s\00"
@.str.9 = [3 x i8] c"%s\00"
@.str.10 = [24 x i8] c"add_nvram_contents end\0A\00"
define i8* @add_nvram_contents(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %13, %15
%17 = add nsw i32 %16, 2
%18 = call i8* @my_malloc(i32 %17)
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = load i8*, i8** %3
%21 = load i8*, i8** %4
%22 = call i32 (i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %21)
%23 = load i8*, i8** %8
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %25, i32** %9
%26 = load i32*, i32** %9
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %32
28: ; preds = %2
%29 = call i8* @my_malloc(i32 2)
store i8* %29, i8** %5
%30 = load i8*, i8** %5
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %30, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
br label %49
32: ; preds = %2
%33 = load i32*, i32** %9
%34 = load i32, i32* @SEEK_END
%35 = call i32 @fseek(i32* %33, i32 0, i32 %34)
%36 = load i32*, i32** %9
%37 = call i32 @ftell(i32* %36)
store i32 %37, i32* %10
%38 = load i32*, i32** %9
%39 = load i32, i32* @SEEK_SET
%40 = call i32 @fseek(i32* %38, i32 0, i32 %39)
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 2
%43 = call i8* @my_malloc(i32 %42)
store i8* %43, i8** %5
%44 = load i32*, i32** %9
%45 = load i8*, i8** %5
%46 = call i32 @fscanf(i32* %44, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %45)
%47 = load i32*, i32** %9
%48 = call i32 @fclose(i32* %47)
br label %49
49: ; preds = %32, %28
%50 = load i8*, i8** %5
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %50)
%52 = load i8*, i8** %5
%53 = call i32 @strlen(i8* %52)
store i32 %53, i32* %6
%54 = load i32, i32* %6
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %68
56: ; preds = %49
%57 = load i8*, i8** %5
%58 = call i32 @strlen(i8* %57)
%59 = load i8*, i8** %8
%60 = call i32 @strlen(i8* %59)
%61 = add nsw i32 %58, %60
%62 = add nsw i32 %61, 2
%63 = call i8* @my_malloc(i32 %62)
store i8* %63, i8** %7
%64 = load i8*, i8** %7
%65 = load i8*, i8** %5
%66 = load i8*, i8** %8
%67 = call i32 (i8*, i8*, ...) @sprintf(i8* %64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i8* %65, i8* %66)
br label %76
68: ; preds = %49
%69 = load i8*, i8** %8
%70 = call i32 @strlen(i8* %69)
%71 = add nsw i32 %70, 1
%72 = call i8* @my_malloc(i32 %71)
store i8* %72, i8** %7
%73 = load i8*, i8** %7
%74 = load i8*, i8** %8
%75 = call i32 (i8*, i8*, ...) @sprintf(i8* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %68, %56
%77 = load i8*, i8** %8
%78 = call i32 @free(i8* %77)
%79 = load i8*, i8** %5
%80 = call i32 @free(i8* %79)
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
%82 = load i8*, i8** %7
ret i8* %82
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"%s>%s\00"
@.str.2 = [33 x i8] c"add_nvram_contents nvp = %s\0A\00"
@.str.3 = [23 x i8] c"/opt/etc/smb_tokenfile\00"
@.str.4 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.6 = [9 x i8] c"%[^\0A]%*c\00"
@.str.7 = [32 x i8] c"add_nvram_contents() - nv = %s\0A\00"
@.str.8 = [6 x i8] c"%s<%s\00"
@str = [25 x i8] c"add_nvram_contents start\00"
@str.11 = [23 x i8] c"add_nvram_contents end\00"
define i8* @add_nvram_contents(i8* %0, i8* %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = add i32 %4, 2
%7 = add i32 %6, %5
%8 = tail call i8* @my_malloc(i32 %7)
%9 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = tail call i8* @my_malloc(i32 2)
store i8 0, i8* %14
br label %25
15: ; preds = %2
%16 = load i32, i32* @SEEK_END
%17 = tail call i32 @fseek(i32* %11, i32 0, i32 %16)
%18 = tail call i32 @ftell(i32* %11)
%19 = load i32, i32* @SEEK_SET
%20 = tail call i32 @fseek(i32* %11, i32 0, i32 %19)
%21 = add nsw i32 %18, 2
%22 = tail call i8* @my_malloc(i32 %21)
%23 = tail call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %22)
%24 = tail call i32 @fclose(i32* %11)
br label %25
25: ; preds = %15, %13
%26 = phi i8* [ %14, %13 ], [ %22, %15 ]
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %26)
%28 = tail call i32 @strlen(i8* %26)
%29 = icmp eq i32 %28, 0
br i1 %29, label %37, label %30
30: ; preds = %25
%31 = tail call i32 @strlen(i8* %26)
%32 = tail call i32 @strlen(i8* %8)
%33 = add i32 %31, 2
%34 = add i32 %33, %32
%35 = tail call i8* @my_malloc(i32 %34)
%36 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %35, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i8* %26, i8* %8)
br label %42
37: ; preds = %25
%38 = tail call i32 @strlen(i8* %8)
%39 = add nsw i32 %38, 1
%40 = tail call i8* @my_malloc(i32 %39)
%41 = tail call i8* @strcpy(i8* dereferenceable(1) %40, i8* dereferenceable(1) %8)
br label %42
42: ; preds = %37, %30
%43 = phi i8* [ %35, %30 ], [ %40, %37 ]
%44 = tail call i32 @free(i8* %8)
%45 = tail call i32 @free(i8* %26)
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.11, i64 0, i64 0))
ret i8* %43
}