#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*/ store_length(int, unsigned char *);
int write(int, unsigned char const *, int);
int write_string(int file, const unsigned char *s, int s_len) {
  unsigned char hdr[2];
  store_length(s_len, hdr);
  return write(file, hdr, 2) < 2 || write(file, s, s_len) < s_len;
}


x86 assembly (clang, -O0):
<write_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x16(%rbp),%rsi
call   1040 <store_length@plt>
mov    -0x4(%rbp),%edi
lea    -0x16(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0x2,%ecx
mov    %al,-0x17(%rbp)
jl     1177 <write_string+0x57>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x17(%rbp)
mov    -0x17(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0x6(%rsp),%r15
mov    %edx,%edi
mov    %r15,%rsi
call   1040 <store_length@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x2,%ecx
jl     116d <write_string+0x4d>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ebx,%ecx
setl   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @write_string(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [2 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%10 = call i32 @store_length(i32 %8, i8* %9)
%11 = load i32, i32* %4
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%13 = call i32 @write(i32 %11, i8* %12, i32 2)
%14 = icmp slt i32 %13, 2
br i1 %14, label %22, label %15
15: ; preds = %3
%16 = load i32, i32* %4
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = call i32 @write(i32 %16, i8* %17, i32 %18)
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br label %22
22: ; preds = %15, %3
%23 = phi i1 [ true, %3 ], [ %21, %15 ]
%24 = zext i1 %23 to i32
ret i32 %24
}

LLVM IR (-O2):
define i32 @write_string(i32 %0, i8* nocapture %1, i32 %2) {
%4 = alloca [2 x i8]
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%6 = call i32 @store_length(i32 %2, i8* %5)
%7 = call i32 @write(i32 %0, i8* %5, i32 2)
%8 = icmp slt i32 %7, 2
br i1 %8, label %13, label %9
9: ; preds = %3
%10 = call i32 @write(i32 %0, i8* %1, i32 %2)
%11 = icmp slt i32 %10, %2
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %9, %3
%14 = phi i32 [ 1, %3 ], [ %12, %9 ]
ret i32 %14
}