#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*/ abfab(int, char *, int);
int strlen(char *);
int ok(int fd, char *str) {
  if ((fd < 0) || (str == NULL)) {
    return (-1);
  }
  if (abfab(fd, "+OK", sizeof(char) * (strlen("+OK"))) < 0) {
    return (-1);
  }
  abfab(fd, " ", sizeof(char));
  abfab(fd, str, sizeof(char) * (strlen(str)));
  abfab(fd, "\r\n", sizeof(char) * 2);
  return (0);
}


x86 assembly (clang, -O0):
<ok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1144 <ok+0x24>
cmpq   $0x0,-0x10(%rbp)
jne    1150 <ok+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <ok+0xc8>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    0xea3(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x14(%rbp),%edi
cltq
shl    $0x0,%rax
mov    %eax,%edx
lea    0xe8c(%rip),%rsi
call   1030 <abfab@plt>
cmp    $0x0,%eax
jge    118e <ok+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <ok+0xc8>
mov    -0x8(%rbp),%edi
lea    0xe6c(%rip),%rsi
mov    $0x1,%edx
call   1030 <abfab@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
cltq
shl    $0x0,%rax
mov    %eax,%edx
call   1030 <abfab@plt>
mov    -0x8(%rbp),%edi
lea    0xe2f(%rip),%rsi
mov    $0x2,%edx
call   1030 <abfab@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ok>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %edi,%edi
js     1195 <ok+0x75>
mov    %rsi,%r14
test   %rsi,%rsi
je     1195 <ok+0x75>
mov    %edi,%ebx
lea    0xebf(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <abfab@plt>
test   %eax,%eax
js     1195 <ok+0x75>
lea    0xea4(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <abfab@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <abfab@plt>
lea    0xe7f(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1030 <abfab@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"+OK\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [3 x i8] c"\0D\0A\00"
define i32 @ok(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %8, %2
store i32 -1, i32* %3
br label %34
12: ; preds = %8
%13 = load i32, i32* %4
%14 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = sext i32 %14 to i64
%16 = mul i64 1, %15
%17 = trunc i64 %16 to i32
%18 = call i32 @abfab(i32 %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %12
store i32 -1, i32* %3
br label %34
21: ; preds = %12
%22 = load i32, i32* %4
%23 = call i32 @abfab(i32 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%24 = load i32, i32* %4
%25 = load i8*, i8** %5
%26 = load i8*, i8** %5
%27 = call i32 @strlen(i8* %26)
%28 = sext i32 %27 to i64
%29 = mul i64 1, %28
%30 = trunc i64 %29 to i32
%31 = call i32 @abfab(i32 %24, i8* %25, i32 %30)
%32 = load i32, i32* %4
%33 = call i32 @abfab(i32 %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
store i32 0, i32* %3
br label %34
34: ; preds = %21, %20, %11
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [4 x i8] c"+OK\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [3 x i8] c"\0D\0A\00"
define i32 @ok(i32 %0, i8* %1) {
%3 = icmp slt i32 %0, 0
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %15, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @abfab(i32 %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = tail call i32 @abfab(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%12 = tail call i32 @strlen(i8* %1)
%13 = tail call i32 @abfab(i32 %0, i8* %1, i32 %12)
%14 = tail call i32 @abfab(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
br label %15
15: ; preds = %6, %2, %10
%16 = phi i32 [ 0, %10 ], [ -1, %2 ], [ -1, %6 ]
ret i32 %16
}