#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 */
struct buffer {
  int dummy;
};

/* Variables and functions */
scalar_t__ buf_bptr(struct buffer const *);
int strlen(char *);
int write(int, scalar_t__, int const);
int /*<<< orphan*/ x_msg(int, char *, char const *);
void buf_write_string_file(const struct buffer *buf, const char *filename,
                           int fd) {
  const int len = strlen((char *)(buf_bptr(buf)));
  const int size = write(fd, (buf_bptr(buf)), len);
  if (size != len) {
    x_msg(((1 << 4) | (1 << 8)), "Write error on file '%s'", filename);
  }
}


x86 assembly (clang, -O0):
<buf_write_string_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <buf_bptr@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <buf_bptr@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     11a8 <buf_write_string_file+0x68>
mov    -0x10(%rbp),%rdx
mov    $0x110,%edi
lea    0xe5d(%rip),%rsi
call   1050 <x_msg@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buf_write_string_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <buf_bptr@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <buf_bptr@plt>
mov    %r15d,%edi
mov    %rax,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
cmp    %ebp,%eax
jne    1183 <buf_write_string_file+0x43>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe76(%rip),%rsi
mov    $0x110,%edi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <x_msg@plt>

LLVM IR (-O0):
%struct.buffer = type { i32 }
@.str = [25 x i8] c"Write error on file '%s'\00"
define void @buf_write_string_file(%struct.buffer* %0, i8* %1, i32 %2) {
%4 = alloca %struct.buffer*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.buffer* %0, %struct.buffer** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load %struct.buffer*, %struct.buffer** %4
%10 = call i64 @buf_bptr(%struct.buffer* %9)
%11 = inttoptr i64 %10 to i8*
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %7
%13 = load i32, i32* %6
%14 = load %struct.buffer*, %struct.buffer** %4
%15 = call i64 @buf_bptr(%struct.buffer* %14)
%16 = load i32, i32* %7
%17 = call i32 @write(i32 %13, i64 %15, i32 %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = load i32, i32* %7
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %3
%22 = load i8*, i8** %5
%23 = call i32 @x_msg(i32 272, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %3
ret void
}

LLVM IR (-O2):
%struct.buffer = type { i32 }
@.str = [25 x i8] c"Write error on file '%s'\00"
define void @buf_write_string_file(%struct.buffer* %0, i8* %1, i32 %2) {
%4 = tail call i64 @buf_bptr(%struct.buffer* %0)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @strlen(i8* %5)
%7 = tail call i64 @buf_bptr(%struct.buffer* %0)
%8 = tail call i32 @write(i32 %2, i64 %7, i32 %6)
%9 = icmp eq i32 %8, %6
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = tail call i32 @x_msg(i32 272, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %12
12: ; preds = %10, %3
ret void
}