#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
void *put_data_in_file(char *data) {
  char name[15] = "data";
  FILE *fichier = NULL;
  strcat(name, ".dat");
  printf("%s", name);
  fichier = fopen(name, "a");
  if (fichier != NULL) {
    fputs(data, fichier);
    fclose(fichier);
  } else {
    printf("Impossible to open the file test.txt");
  }
  return NULL;
}


x86 assembly (clang, -O0):
<put_data_in_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xe9d(%rip),%rax
mov    %rax,-0x17(%rbp)
mov    0xe9b(%rip),%eax
mov    %eax,-0xf(%rbp)
mov    0xe95(%rip),%ax
mov    %ax,-0xb(%rbp)
mov    0xe8d(%rip),%al
mov    %al,-0x9(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x17(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1070 <strcat@plt>
lea    -0x17(%rbp),%rsi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x17(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e8 <put_data_in_file+0x98>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11f6 <put_data_in_file+0xa6>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_data_in_file>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
movq   $0x0,0xf(%rsp)
movq   $0x61746164,0x8(%rsp)
74 61
lea    0xe9c(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strcat@plt>
lea    0xe8d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11bd <put_data_in_file+0x6d>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11cb <put_data_in_file+0x7b>
lea    0xe55(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.put_data_in_file.name = [15 x i8] c"data\00\00\00\00\00\00\00\00\00\00\00"
@.str = [5 x i8] c".dat\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [37 x i8] c"Impossible to open the file test.txt\00"
define i8* @put_data_in_file(i8* %0) {
%2 = alloca i8*
%3 = alloca [15 x i8]
%4 = alloca i32*
store i8* %0, i8** %2
%5 = bitcast [15 x i8]* %3 to i8*
store i32* null, i32** %4
%6 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%7 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %1
%15 = load i8*, i8** %2
%16 = load i32*, i32** %4
%17 = call i32 @fputs(i8* %15, i32* %16)
%18 = load i32*, i32** %4
%19 = call i32 @fclose(i32* %18)
br label %22
20: ; preds = %1
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %14
ret i8* null
}

LLVM IR (-O2):
@__const.put_data_in_file.name = [15 x i8] c"data\00\00\00\00\00\00\00\00\00\00\00"
@.str = [5 x i8] c".dat\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [37 x i8] c"Impossible to open the file test.txt\00"
define noalias i8* @put_data_in_file(i8* nocapture %0) {
%2 = alloca [15 x i8]
%3 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%6 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = call i32 @fputs(i8* %0, i32* %6)
%10 = call i32 @fclose(i32* %6)
br label %13
11: ; preds = %1
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
ret i8* null
}