#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 */
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ SSL;

/* Variables and functions */
scalar_t__ SSL_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ SSL_write(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ close(int);
int read(int, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int uds_client_connect(char const *);
int /*<<< orphan*/ write(int, char *, int);
void client_do(SSL *ssl, const char *sock_name) {
  char buffer[256];
  int num, sock = uds_client_connect(sock_name);
  while ((num = SSL_read(ssl, buffer, sizeof(buffer)) > 0)) {
    buffer[num] = 0;
    if (!strcmp(buffer, "exit"))
      break;
    write(sock, buffer, num);
    num = read(sock, buffer, sizeof(buffer));
    SSL_write(ssl, buffer, num);
  }
  close(sock);
}


x86 assembly (clang, -O0):
<client_do>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <uds_client_connect@plt>
mov    %eax,-0x118(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1070 <SSL_read@plt>
cmp    $0x0,%rax
setg   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x114(%rbp)
test   $0x1,%al
jne    11c9 <client_do+0x59>
jmp    1249 <client_do+0xd9>
movslq -0x114(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    11f9 <client_do+0x89>
jmp    1249 <client_do+0xd9>
mov    -0x118(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    -0x114(%rbp),%edx
call   1050 <write@plt>
mov    -0x118(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1080 <read@plt>
mov    %eax,-0x114(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    -0x114(%rbp),%edx
call   1040 <SSL_write@plt>
jmp    1192 <client_do+0x22>
mov    -0x118(%rbp),%edi
call   1060 <close@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_do>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <uds_client_connect@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0x100,%edx
call   1070 <SSL_read@plt>
test   %rax,%rax
jle    11f4 <client_do+0x94>
mov    $0x74697865,%r15d
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
movb   $0x0,0x1(%rsp)
mov    (%rsp),%eax
xor    %r15d,%eax
movzbl 0x4(%rsp),%ecx
or     %eax,%ecx
je     11f4 <client_do+0x94>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1080 <read@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <SSL_write@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1070 <SSL_read@plt>
test   %rax,%rax
jg     11a0 <client_do+0x40>
mov    %ebp,%edi
call   1060 <close@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"exit\00"
define void @client_do(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @uds_client_connect(i8* %8)
store i32 %9, i32* %7
br label %10
10: ; preds = %24, %2
%11 = load i32*, i32** %3
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%13 = call i64 @SSL_read(i32* %11, i8* %12, i32 256)
%14 = icmp sgt i64 %13, 0
%15 = zext i1 %14 to i32
store i32 %15, i32* %6
br i1 %14, label %16, label %36
16: ; preds = %10
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%21 = call i32 @strcmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %16
br label %36
24: ; preds = %16
%25 = load i32, i32* %7
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%27 = load i32, i32* %6
%28 = call i32 @write(i32 %25, i8* %26, i32 %27)
%29 = load i32, i32* %7
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%31 = call i32 @read(i32 %29, i8* %30, i32 256)
store i32 %31, i32* %6
%32 = load i32*, i32** %3
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%34 = load i32, i32* %6
%35 = call i32 @SSL_write(i32* %32, i8* %33, i32 %34)
br label %10
36: ; preds = %23, %10
%37 = load i32, i32* %7
%38 = call i32 @close(i32 %37)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"exit\00"
define void @client_do(i32* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @uds_client_connect(i8* %1)
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 1
%7 = call i64 @SSL_read(i32* %0, i8* %4, i32 256)
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %2, %12
store i8 0, i8* %6
%10 = call i32 @bcmp(i8* dereferenceable(5) %4, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 5)
%11 = icmp eq i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = call i32 @write(i32 %5, i8* %4, i32 1)
%14 = call i32 @read(i32 %5, i8* %4, i32 256)
%15 = call i32 @SSL_write(i32* %0, i8* %4, i32 %14)
%16 = call i64 @SSL_read(i32* %0, i8* %4, i32 256)
%17 = icmp sgt i64 %16, 0
br i1 %17, label %9, label %18
18: ; preds = %12, %9, %2
%19 = call i32 @close(i32 %5)
ret void
}