#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*/ printf(char *, char *);
int read(int, char *, int);
void *read_fun(void *args) {
  int fd = *(int *)args;
  char data[512];
  int i, ret;
  for (i = 0; i < 2; i++) {
    ret = read(fd, data, 512);
    data[ret] = '\0';
    printf("letto: %s\n", data);
  }
}


x86 assembly (clang, -O0):
<read_fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x224(%rbp)
cmpl   $0x2,-0x224(%rbp)
jge    119f <read_fun+0x7f>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1040 <read@plt>
mov    %eax,-0x228(%rbp)
movslq -0x228(%rbp),%rax
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rsi
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
jmp    1142 <read_fun+0x22>
mov    -0x8(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_fun>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    (%rdi),%ebx
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1040 <read@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xeb3(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1040 <read@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"letto: %s\0A\00"
define noalias i8* @read_fun(i8* nocapture %0) {
%2 = alloca [512 x i8]
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%6 = call i32 @read(i32 %4, i8* %5, i32 512)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %7
store i8 0, i8* %8
%9 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %5)
%10 = call i32 @read(i32 %4, i8* %5, i32 512)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %11
store i8 0, i8* %12
%13 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %5)
ret i8* undef
}