#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 write(int, char *, int);
int send_to_pipe(int *fd, char *s) {
  int count = 0;
  printf("writing to %d\n", fd[1]);
  do {
    if (write(fd[1], s, 1) == -1)
      perror("snd");
    count++;
  } while (*s++);
  return count;
}


x86 assembly (clang, -O0):
<send_to_pipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xeab(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1184 <send_to_pipe+0x54>
lea    0xe90(%rip),%rdi
call   1050 <perror@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
cmpb   $0x0,(%rax)
jne    115a <send_to_pipe+0x2a>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_to_pipe>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x4(%rdi),%esi
lea    0xeb7(%rip),%rdi
call   1040 <printf@plt>
xor    %ebx,%ebx
lea    0xeb8(%rip),%r12
jmp    116b <send_to_pipe+0x3b>
nopl   0x0(%rax)
add    $0x1,%rbx
cmpb   $0x0,0x0(%r13)
je     118f <send_to_pipe+0x5f>
lea    (%r14,%rbx,1),%r13
mov    0x4(%r15),%edi
mov    %r13,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1160 <send_to_pipe+0x30>
mov    %r12,%rdi
call   1050 <perror@plt>
jmp    1160 <send_to_pipe+0x30>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"writing to %d\0A\00"
@.str.1 = [4 x i8] c"snd\00"
define i32 @send_to_pipe(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%6 = load i32*, i32** %3
%7 = getelementptr inbounds i32, i32* %6, i64 1
%8 = load i32, i32* %7
%9 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %22, %2
%11 = load i32*, i32** %3
%12 = getelementptr inbounds i32, i32* %11, i64 1
%13 = load i32, i32* %12
%14 = load i8*, i8** %4
%15 = call i32 @write(i32 %13, i8* %14, i32 1)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %10
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %22
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
%25 = load i8, i8* %23
%26 = icmp ne i8 %25, 0
br i1 %26, label %10, label %27
27: ; preds = %22
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
@.str = [15 x i8] c"writing to %d\0A\00"
@.str.1 = [4 x i8] c"snd\00"
define i32 @send_to_pipe(i32* nocapture %0, i8* nocapture %1) {
%3 = getelementptr inbounds i32, i32* %0, i64 1
%4 = load i32, i32* %3
%5 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %6
6: ; preds = %14, %2
%7 = phi i8* [ %1, %2 ], [ %16, %14 ]
%8 = phi i32 [ 0, %2 ], [ %15, %14 ]
%9 = load i32, i32* %3
%10 = tail call i32 @write(i32 %9, i8* %7, i32 1)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = tail call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %6
%15 = add nuw nsw i32 %8, 1
%16 = getelementptr inbounds i8, i8* %7, i64 1
%17 = load i8, i8* %7
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %6
19: ; preds = %14
ret i32 %15
}