#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 atoi(char *);
int /*<<< orphan*/ free(char *);
char *socket_receive_smtp(int);
char *strdup(char *);
int strlen(char *);
int socket_get_smtp_code(int sock, char **message) {
  int code;
  char *buf = socket_receive_smtp(sock);
  if (!buf || strlen(buf) < 4 || (buf[3] != ' ' && buf[3] != '-')) {
    free(buf);
    return 999;
  }
  buf[3] = 0;
  code = atoi(buf);
  if (message)
    *message = strdup(buf + 4);
  free(buf);
  return code;
}


x86 assembly (clang, -O0):
<socket_get_smtp_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <socket_receive_smtp@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11aa <socket_get_smtp_code+0x5a>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jl     11aa <socket_get_smtp_code+0x5a>
mov    -0x20(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x20,%eax
je     11bf <socket_get_smtp_code+0x6f>
mov    -0x20(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x2d,%eax
je     11bf <socket_get_smtp_code+0x6f>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x3e7,-0x4(%rbp)
jmp    1204 <socket_get_smtp_code+0xb4>
mov    -0x20(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f5 <socket_get_smtp_code+0xa5>
mov    -0x20(%rbp),%rdi
add    $0x4,%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_get_smtp_code>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
call   1050 <socket_receive_smtp@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a8 <socket_get_smtp_code+0x58>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jl     11a8 <socket_get_smtp_code+0x58>
mov    0x3(%rbx),%al
cmp    $0x20,%al
je     117c <socket_get_smtp_code+0x2c>
cmp    $0x2d,%al
jne    11a8 <socket_get_smtp_code+0x58>
movb   $0x0,0x3(%rbx)
mov    %rbx,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
test   %r14,%r14
je     119e <socket_get_smtp_code+0x4e>
mov    %rbx,%rdi
add    $0x4,%rdi
call   1070 <strdup@plt>
mov    %rax,(%r14)
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11b5 <socket_get_smtp_code+0x65>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x3e7,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @socket_get_smtp_code(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = call i8* @socket_receive_smtp(i32 %8)
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %28
12: ; preds = %2
%13 = load i8*, i8** %7
%14 = call i32 @strlen(i8* %13)
%15 = icmp slt i32 %14, 4
br i1 %15, label %28, label %16
16: ; preds = %12
%17 = load i8*, i8** %7
%18 = getelementptr inbounds i8, i8* %17, i64 3
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 32
br i1 %21, label %22, label %31
22: ; preds = %16
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i64 3
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 45
br i1 %27, label %28, label %31
28: ; preds = %22, %12, %2
%29 = load i8*, i8** %7
%30 = call i32 @free(i8* %29)
store i32 999, i32* %3
br label %47
31: ; preds = %22, %16
%32 = load i8*, i8** %7
%33 = getelementptr inbounds i8, i8* %32, i64 3
store i8 0, i8* %33
%34 = load i8*, i8** %7
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %6
%36 = load i8**, i8*** %5
%37 = icmp ne i8** %36, null
br i1 %37, label %38, label %43
38: ; preds = %31
%39 = load i8*, i8** %7
%40 = getelementptr inbounds i8, i8* %39, i64 4
%41 = call i8* @strdup(i8* %40)
%42 = load i8**, i8*** %5
store i8* %41, i8** %42
br label %43
43: ; preds = %38, %31
%44 = load i8*, i8** %7
%45 = call i32 @free(i8* %44)
%46 = load i32, i32* %6
store i32 %46, i32* %3
br label %47
47: ; preds = %43, %28
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
define i32 @socket_get_smtp_code(i32 %0, i8** writeonly %1) {
%3 = tail call i8* @socket_receive_smtp(i32 %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %3)
%7 = icmp slt i32 %6, 4
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %3, i64 3
%10 = load i8, i8* %9
switch i8 %10, label %11 [
i8 32, label %13
i8 45, label %13
]
11: ; preds = %8, %5, %2
%12 = tail call i32 @free(i8* %3)
br label %21
13: ; preds = %8, %8
store i8 0, i8* %9
%14 = tail call i32 @atoi(i8* %3)
%15 = icmp eq i8** %1, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %3, i64 4
%18 = tail call i8* @strdup(i8* %17)
store i8* %18, i8** %1
br label %19
19: ; preds = %16, %13
%20 = tail call i32 @free(i8* %3)
br label %21
21: ; preds = %19, %11
%22 = phi i32 [ 999, %11 ], [ %14, %19 ]
ret i32 %22
}