#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 buffer_open_output(char const *);
scalar_t__ full_write(int, char const *, scalar_t__);
scalar_t__ strlen(char const *);
int buffer_save(const char *tag, const char *data) {
  int fd;
  fd = buffer_open_output(tag);
  if (fd < 0)
    return 0;
  if (full_write(fd, data, strlen(data)) == strlen(data)) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<buffer_save>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <buffer_open_output@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1162 <buffer_save+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11b8 <buffer_save+0x88>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
call   1040 <full_write@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jne    11b1 <buffer_save+0x81>
movl   $0x1,-0x4(%rbp)
jmp    11b8 <buffer_save+0x88>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffer_save>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1050 <buffer_open_output@plt>
test   %eax,%eax
js     116e <buffer_save+0x3e>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <full_write@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rbp
sete   %al
jmp    1170 <buffer_save+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @buffer_save(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i32 @buffer_open_output(i8* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %23
12: ; preds = %2
%13 = load i32, i32* %6
%14 = load i8*, i8** %5
%15 = load i8*, i8** %5
%16 = call i64 @strlen(i8* %15)
%17 = call i64 @full_write(i32 %13, i8* %14, i64 %16)
%18 = load i8*, i8** %5
%19 = call i64 @strlen(i8* %18)
%20 = icmp eq i64 %17, %19
br i1 %20, label %21, label %22
21: ; preds = %12
store i32 1, i32* %3
br label %23
22: ; preds = %12
store i32 0, i32* %3
br label %23
23: ; preds = %22, %21, %11
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @buffer_save(i8* %0, i8* %1) {
%3 = tail call i32 @buffer_open_output(i8* %0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = tail call i64 @full_write(i32 %3, i8* %1, i64 %6)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%9 = icmp eq i64 %7, %8
%10 = zext i1 %9 to i32
br label %11
11: ; preds = %5, %2
%12 = phi i32 [ 0, %2 ], [ %10, %5 ]
ret i32 %12
}