#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*/ input;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, char *, int);
void sapi_read_event_cb(void *cbctx) {
  int *s = cbctx;
  char input[100];
  int len;
  memset(input, 0, sizeof(input));
  printf("address %d\n", *s);
  len = read(*s, input, sizeof(input));
  if (len > 0) {
    printf("read %d from input : %s\n", len, input);
    return;
  } else {
    printf("read error from %d\n", *s);
  }
}


x86 assembly (clang, -O0):
<sapi_read_event_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1050 <read@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jle    11af <sapi_read_event_cb+0x7f>
mov    -0x84(%rbp),%esi
lea    -0x80(%rbp),%rdx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c3 <sapi_read_event_cb+0x93>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sapi_read_event_cb>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
mov    (%rbx),%esi
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rbx),%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    1184 <sapi_read_event_cb+0x54>
lea    0xe96(%rip),%rdi
mov    %rsp,%rdx
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1194 <sapi_read_event_cb+0x64>
mov    (%rbx),%esi
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"address %d\0A\00"
@.str.1 = [25 x i8] c"read %d from input : %s\0A\00"
@.str.2 = [20 x i8] c"read error from %d\0A\00"
define void @sapi_read_event_cb(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [100 x i8]
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to i32*
store i32* %7, i32** %3
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 100)
%10 = load i32*, i32** %3
%11 = load i32, i32* %10
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32*, i32** %3
%14 = load i32, i32* %13
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%16 = call i32 @read(i32 %14, i8* %15, i32 100)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %1
%20 = load i32, i32* %5
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %20, i8* %21)
br label %27
23: ; preds = %1
%24 = load i32*, i32** %3
%25 = load i32, i32* %24
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %19, %23
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"address %d\0A\00"
@.str.1 = [25 x i8] c"read %d from input : %s\0A\00"
@.str.2 = [20 x i8] c"read error from %d\0A\00"
define void @sapi_read_event_cb(i8* nocapture %0) {
%2 = alloca [100 x i8]
%3 = bitcast i8* %0 to i32*
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 100)
%6 = load i32, i32* %3
%7 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* %3
%9 = call i32 @read(i32 %8, i8* %4, i32 100)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %9, i8* %4)
br label %16
13: ; preds = %1
%14 = load i32, i32* %3
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %13, %11
ret void
}