#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 */

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int smp_file_write_apend(char const *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int smp_test_apend_file(const char *file) {
  int ret = 0;
  char *buf = "~~~xvhsdbvhsdhsbhbxhsdhfsdhfvshdbvhsdbvhsbhvbsj~";
  if (file == NULL)
    return (-1);
  ret = smp_file_write_apend(file, buf, strlen(buf));
  if (ret == (-1)) {
    perror("write file apend err\n");
    return (-1);
  }
  printf("apend file %d\n", ret);
  return (0);
}


x86 assembly (clang, -O0):
<smp_test_apend_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xea6(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1175 <smp_test_apend_file+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <smp_test_apend_file+0x98>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <smp_file_write_apend@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c2 <smp_test_apend_file+0x82>
lea    0xe80(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <smp_test_apend_file+0x98>
mov    -0x14(%rbp),%esi
lea    0xe7b(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smp_test_apend_file>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     1182 <smp_test_apend_file+0x42>
mov    %rdi,%rbx
lea    0xea8(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <smp_file_write_apend@plt>
cmp    $0xffffffff,%eax
je     1189 <smp_test_apend_file+0x49>
lea    0xece(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xea1(%rip),%rdi
call   1060 <perror@plt>
jmp    1182 <smp_test_apend_file+0x42>

LLVM IR (-O0):
@.str = [49 x i8] c"~~~xvhsdbvhsdhsbhbxhsdhfsdhfvshdbvhsdbvhsbhvbsj~\00"
@.str.1 = [22 x i8] c"write file apend err\0A\00"
@.str.2 = [15 x i8] c"apend file %d\0A\00"
define i32 @smp_test_apend_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %4
store i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %22
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8*, i8** %5
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = call i32 @smp_file_write_apend(i8* %10, i8* %11, i32 %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %22
19: ; preds = %9
%20 = load i32, i32* %4
%21 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %20)
store i32 0, i32* %2
br label %22
22: ; preds = %19, %17, %8
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [49 x i8] c"~~~xvhsdbvhsdhsbhbxhsdhfsdhfvshdbvhsdbvhsbhvbsj~\00"
@.str.1 = [22 x i8] c"write file apend err\0A\00"
@.str.2 = [15 x i8] c"apend file %d\0A\00"
define i32 @smp_test_apend_file(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @smp_file_write_apend(i8* %0, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %11
9: ; preds = %3
%10 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %5)
br label %11
11: ; preds = %1, %9, %7
%12 = phi i32 [ -1, %7 ], [ 0, %9 ], [ -1, %1 ]
ret i32 %12
}