#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 SocketBuffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ buffWrite(char *, int, struct SocketBuffer *);
void writeString(char *string, struct SocketBuffer *buff) {
  int size = 0;
  char strChar = string[0];
  while (strChar != '\0') {
    size++;
    strChar = string[size];
  }
  size++;
  buffWrite(string, size, buff);
}


x86 assembly (clang, -O0):
<writeString>:
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    (%rax),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
cmp    $0x0,%eax
je     1159 <writeString+0x49>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
jmp    1130 <writeString+0x20>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <buffWrite@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeString>:
mov    %rsi,%rdx
cmpb   $0x0,(%rdi)
je     1131 <writeString+0x21>
mov    $0x1,%esi
nopl   (%rax)
movslq %esi,%rax
lea    0x1(%rax),%esi
cmpb   $0x0,(%rdi,%rax,1)
jne    1120 <writeString+0x10>
jmp    1030 <buffWrite@plt>
mov    $0x1,%esi
jmp    1030 <buffWrite@plt>

LLVM IR (-O0):
%struct.SocketBuffer = type { i32 }
define void @writeString(i8* %0, %struct.SocketBuffer* %1) {
%3 = alloca i8*
%4 = alloca %struct.SocketBuffer*
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %3
store %struct.SocketBuffer* %1, %struct.SocketBuffer** %4
store i32 0, i32* %5
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
store i8 %9, i8* %6
br label %10
10: ; preds = %14, %2
%11 = load i8, i8* %6
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1
store i32 %16, i32* %5
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
store i8 %21, i8* %6
br label %10
22: ; preds = %10
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
%25 = load i8*, i8** %3
%26 = load i32, i32* %5
%27 = load %struct.SocketBuffer*, %struct.SocketBuffer** %4
%28 = call i32 @buffWrite(i8* %25, i32 %26, %struct.SocketBuffer* %27)
ret void
}

LLVM IR (-O2):
%struct.SocketBuffer = type { i32 }
define void @writeString(i8* %0, %struct.SocketBuffer* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %2, %5
%6 = phi i32 [ %9, %5 ], [ 1, %2 ]
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = add i32 %6, 1
%10 = load i8, i8* %8
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %5
12: ; preds = %5, %2
%13 = phi i32 [ 1, %2 ], [ %9, %5 ]
%14 = tail call i32 @buffWrite(i8* %0, i32 %13, %struct.SocketBuffer* %1)
ret void
}