#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 */
char *extract_str(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ free(char *);
int strlen(char *);
int insert(char *message) {
  char *requete;
  int len;
  FILE *fp;
  fp = fopen("hotel", "a");
  if (fp == NULL)
    return 1;
  requete = extract_str(message, 1);
  len = strlen(requete);
  if (fprintf(fp, "%s", (message + len + 1)) != strlen(message + len + 1)) {
    fclose(fp);
    free(requete);
    return 1;
  }
  fclose(fp);
  free(requete);
  return 0;
}


x86 assembly (clang, -O0):
<insert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8d(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119a <insert+0x3a>
movl   $0x1,-0x4(%rbp)
jmp    1232 <insert+0xd2>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1070 <extract_str@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
movslq -0x1c(%rbp),%rax
add    %rax,%rdx
add    $0x1,%rdx
lea    0xe36(%rip),%rsi
call   1060 <fprintf@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
je     1219 <insert+0xb9>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1232 <insert+0xd2>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe8f(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11df <insert+0x7f>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x1,%esi
call   1070 <extract_str@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <strlen@plt>
cltq
lea    (%r14,%rax,1),%rbp
add    $0x1,%rbp
lea    0xe5a(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1060 <fprintf@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1050 <strlen@plt>
xor    %ebp,%ebp
cmp    %eax,%r14d
setne  %bpl
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11e4 <insert+0x84>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"hotel\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @insert(i8* %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = tail call i8* @extract_str(i8* %0, i32 1)
%6 = tail call i32 @strlen(i8* %5)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = tail call i32 @strlen(i8* %9)
%12 = icmp ne i32 %10, %11
%13 = tail call i32 @fclose(i32* %2)
%14 = tail call i32 @free(i8* %5)
%15 = zext i1 %12 to i32
br label %16
16: ; preds = %4, %1
%17 = phi i32 [ 1, %1 ], [ %15, %4 ]
ret i32 %17
}