#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
char *myfunction(char *, int);
int main(int argc, char **argv) {
  char *input;
  input = (char *)malloc(sizeof(char) * 20);
  FILE *fd = fopen(argv[1], "r");
  fgets(input, sizeof input, fd);
  char *buf;
  int len;
  len = input[0];
  buf = myfunction(input, len);
  free(buf);
  free(input);
  return 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)
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x8,%esi
call   1040 <fgets@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1070 <myfunction@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%r14),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
movsbl (%rbx),%esi
mov    %rbx,%rdi
call   1070 <myfunction@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i64 @malloc(i32 20)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %7
%16 = load i8*, i8** %6
%17 = load i32*, i32** %7
%18 = call i32 @fgets(i8* %16, i32 8, i32* %17)
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
store i32 %22, i32* %9
%23 = load i8*, i8** %6
%24 = load i32, i32* %9
%25 = call i8* @myfunction(i8* %23, i32 %24)
store i8* %25, i8** %8
%26 = load i8*, i8** %8
%27 = call i32 @free(i8* %26)
%28 = load i8*, i8** %6
%29 = call i32 @free(i8* %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i64 @malloc(i32 20)
%4 = inttoptr i64 %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @fgets(i8* %4, i32 8, i32* %7)
%9 = load i8, i8* %4
%10 = sext i8 %9 to i32
%11 = tail call i8* @myfunction(i8* %4, i32 %10)
%12 = tail call i32 @free(i8* %11)
%13 = tail call i32 @free(i8* %4)
ret i32 0
}