#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_write_file(char const *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int smp_test_write_file(const char *file) {
  int ret = 0;
  char *buf = "xvhsdbvhsdhsbhbxhsdhfsdhfvshdbvhsdbvhsbhvbsj";
  if (file == NULL)
    return (-1);
  ret = smp_write_file(file, buf, strlen(buf));
  if (ret == (-1)) {
    perror("write file err\n");
    return ret;
  }
  printf("write size %d\n", ret);
  return (0);
}


x86 assembly (clang, -O0):
<smp_test_write_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_write_file+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <smp_test_write_file+0x97>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1050 <smp_write_file@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c1 <smp_test_write_file+0x81>
lea    0xe7c(%rip),%rdi
call   1060 <perror@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d7 <smp_test_write_file+0x97>
mov    -0x14(%rbp),%esi
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@.str = [45 x i8] c"xvhsdbvhsdhsbhbxhsdhfsdhfvshdbvhsdbvhsbhvbsj\00"
@.str.1 = [16 x i8] c"write file err\0A\00"
@.str.2 = [15 x i8] c"write size %d\0A\00"
define i32 @smp_test_write_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 ([45 x i8], [45 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 %23
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_write_file(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 %20
17: ; preds = %9
%18 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* %4
store i32 %19, i32* %2
br label %23
20: ; preds = %9
%21 = load i32, i32* %4
%22 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %21)
store i32 0, i32* %2
br label %23
23: ; preds = %20, %17, %8
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [45 x i8] c"xvhsdbvhsdhsbhbxhsdhfsdhfvshdbvhsdbvhsbhvbsj\00"
@.str.1 = [16 x i8] c"write file err\0A\00"
@.str.2 = [15 x i8] c"write size %d\0A\00"
define i32 @smp_test_write_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 ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @smp_write_file(i8* %0, i8* getelementptr inbounds ([45 x i8], [45 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 ([16 x i8], [16 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
}