#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*/ free(char *);
size_t fwrite(char *, int, int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int snprintf(char *, int, char *, long);
size_t set_value(FILE *fp, long val) {
  char *tmp = malloc(20 * sizeof(char));
  memset(tmp, 0, 20 * sizeof(char));
  int conv = snprintf(tmp, 20, "%ld", val);
  size_t write = fwrite(tmp, sizeof(char), 20, fp);
  free(tmp);
  return write;
}


x86 assembly (clang, -O0):
<set_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x14,%esi
lea    0xe6e(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x14,%edx
call   1070 <fwrite@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_value>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
lea    0xe82(%rip),%rdx
mov    %rbx,%rdi
mov    $0x14,%esi
mov    %r15,%rcx
call   1040 <snprintf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x14,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
define i64 @set_value(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
store i32* %0, i32** %3
store i64 %1, i64* %4
%8 = call i8* @malloc(i32 20)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @memset(i8* %9, i32 0, i32 20)
%11 = load i8*, i8** %5
%12 = load i64, i64* %4
%13 = call i32 @snprintf(i8* %11, i32 20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %12)
store i32 %13, i32* %6
%14 = load i8*, i8** %5
%15 = load i32*, i32** %3
%16 = call i64 @fwrite(i8* %14, i32 1, i32 20, i32* %15)
store i64 %16, i64* %7
%17 = load i8*, i8** %5
%18 = call i32 @free(i8* %17)
%19 = load i64, i64* %7
ret i64 %19
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
define i64 @set_value(i32* nocapture %0, i64 %1) {
%3 = tail call dereferenceable_or_null(20) i8* @malloc(i32 20)
%4 = tail call i32 @memset(i8* %3, i32 0, i32 20)
%5 = tail call i32 @snprintf(i8* %3, i32 20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %1)
%6 = tail call i64 @fwrite(i8* %3, i32 1, i32 20, i32* %0)
%7 = tail call i32 @free(i8* %3)
ret i64 %6
}