#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*/ memset(char *, int /*<<< orphan*/, int);
int readData(int, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int readMsg(int fd, char *head, char *value) {
  char buffer[512];
  int ret;
  memset(buffer, 0, 512);
  ret = readData(fd, buffer);
  sscanf(buffer, "%s", head);
  strcpy(value, &buffer[strlen(head) + 1]);
  return ret;
}


x86 assembly (clang, -O0):
<readMsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x220(%rbp),%rsi
call   1060 <readData@plt>
mov    %eax,-0x224(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe60(%rip),%rsi
call   1070 <sscanf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x230(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x230(%rbp),%rdi
add    $0x1,%eax
cltq
lea    -0x220(%rbp),%rsi
add    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x224(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readMsg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %r15,%rsi
call   1060 <readData@plt>
mov    %eax,%ebp
lea    0xe76(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
call   1070 <sscanf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%r15,1),%rsi
add    $0x1,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %ebp,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i32 @readMsg(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [512 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 512)
%11 = load i32, i32* %4
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%13 = call i32 @readData(i32 %11, i8* %12)
store i32 %13, i32* %8
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%15 = load i8*, i8** %5
%16 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %6
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 %21
%23 = call i32 @strcpy(i8* %17, i8* %22)
%24 = load i32, i32* %8
ret i32 %24
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @readMsg(i32 %0, i8* %1, i8* %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 512)
%7 = call i32 @readData(i32 %0, i8* %5)
%8 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%9 = call i32 @strlen(i8* %1)
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %11
%13 = call i32 @strcpy(i8* %2, i8* %12)
ret i32 %7
}