#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, int *, char *);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
char toupper(char);
void figlioConsumatore(int fd[2]) {
  char line[128], tmp[128];
  int msgCons = 0;
  int i;
  pid_t pidProduttore;
  close(fd[1]);
  while (1) {
    read(fd[0], tmp, 128);
    sscanf(tmp, "%5d%s", &pidProduttore, line);
    if (strcmp(line, "end") == 0)
      break;
    for (i = 0; i < strlen(line); i++) {
      line[i] = toupper(line[i]);
    }
    fprintf(stdout, "Consumatore (pidProduttore=%d): %s\n", pidProduttore,
            line);
    fflush(stdout);
    msgCons++;
  }
  exit(msgCons);
}


x86 assembly (clang, -O0):
<figlioConsumatore>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x114(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rsi
mov    $0x80,%edx
call   1060 <read@plt>
lea    -0x110(%rbp),%rdi
lea    -0x90(%rbp),%rcx
lea    0xe1f(%rip),%rsi
lea    -0x11c(%rbp),%rdx
call   10a0 <sscanf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    120f <figlioConsumatore+0x7f>
jmp    12bd <figlioConsumatore+0x12d>
movl   $0x0,-0x118(%rbp)
mov    -0x118(%rbp),%eax
mov    %eax,-0x120(%rbp)
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x120(%rbp),%eax
cmp    %ecx,%eax
jge    1279 <figlioConsumatore+0xe9>
movslq -0x118(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%edi
ff
call   1030 <toupper@plt>
mov    %al,%cl
movslq -0x118(%rbp),%rax
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    1219 <figlioConsumatore+0x89>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
mov    -0x11c(%rbp),%edx
lea    -0x90(%rbp),%rcx
lea    0xd74(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    11b5 <figlioConsumatore+0x25>
mov    -0x114(%rbp),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<figlioConsumatore>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%r14
mov    0x4(%rdi),%edi
call   1050 <close@plt>
mov    (%r14),%edi
lea    0x90(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x80,%edx
call   1060 <read@plt>
lea    0xe35(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rcx
call   10a0 <sscanf@plt>
lea    0xe1f(%rip),%rsi
mov    %rbp,%rdi
call   1070 <strcmp@plt>
xor    %r15d,%r15d
test   %rax,%rax
jne    11ff <figlioConsumatore+0x6f>
mov    %r15d,%edi
call   10b0 <exit@plt>
xor    %r15d,%r15d
lea    0x10(%rsp),%rbx
mov    0x2dd2(%rip),%r12
lea    0x90(%rsp),%r13
jmp    1283 <figlioConsumatore+0xf3>
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    0xc(%rsp),%edx
lea    0xddb(%rip),%rsi
mov    %rbx,%rcx
call   1080 <fprintf@plt>
mov    (%r12),%edi
call   1090 <fflush@plt>
add    $0x1,%r15d
mov    (%r14),%edi
mov    %r13,%rsi
mov    $0x80,%edx
call   1060 <read@plt>
mov    %r13,%rdi
lea    0xda2(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rcx
call   10a0 <sscanf@plt>
mov    %rbx,%rdi
lea    0xd91(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11f7 <figlioConsumatore+0x67>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1220 <figlioConsumatore+0x90>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl 0x10(%rsp,%rbp,1),%edi
call   1030 <toupper@plt>
mov    %al,0x10(%rsp,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     12a0 <figlioConsumatore+0x110>
jmp    1220 <figlioConsumatore+0x90>

LLVM IR (-O0):
@.str = [6 x i8] c"%5d%s\00"
@.str.1 = [4 x i8] c"end\00"
@stdout = global i32 0
@.str.2 = [36 x i8] c"Consumatore (pidProduttore=%d): %s\0A\00"
define void @figlioConsumatore(i32* %0) {
%2 = alloca i32*
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %5
%8 = load i32*, i32** %2
%9 = getelementptr inbounds i32, i32* %8, i64 1
%10 = load i32, i32* %9
%11 = call i32 @close(i32 %10)
br label %12
12: ; preds = %1, %43
%13 = load i32*, i32** %2
%14 = getelementptr inbounds i32, i32* %13, i64 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%17 = call i32 @read(i32 %15, i8* %16, i32 128)
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%20 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %7, i8* %19)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %12
br label %52
25: ; preds = %12
store i32 0, i32* %6
br label %26
26: ; preds = %40, %25
%27 = load i32, i32* %6
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = icmp slt i32 %27, %29
br i1 %30, label %31, label %43
31: ; preds = %26
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = call signext i8 @toupper(i8 signext %35)
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %38
store i8 %36, i8* %39
br label %40
40: ; preds = %31
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %26
43: ; preds = %26
%44 = load i32, i32* @stdout
%45 = load i32, i32* %7
%46 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%47 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %45, i8* %46)
%48 = load i32, i32* @stdout
%49 = call i32 @fflush(i32 %48)
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
br label %12
52: ; preds = %24
%53 = load i32, i32* %5
%54 = call i32 @exit(i32 %53)
unreachable
}

LLVM IR (-O2):
@.str = [6 x i8] c"%5d%s\00"
@.str.1 = [4 x i8] c"end\00"
@stdout = global i32 0
@.str.2 = [36 x i8] c"Consumatore (pidProduttore=%d): %s\0A\00"
define void @figlioConsumatore(i32* nocapture %0) {
%2 = alloca [128 x i8]
%3 = alloca [128 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds i32, i32* %0, i64 1
%9 = load i32, i32* %8
%10 = tail call i32 @close(i32 %9)
%11 = load i32, i32* %0
%12 = call i32 @read(i32 %11, i8* %6, i32 128)
%13 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %4, i8* %5)
%14 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %41, label %16
16: ; preds = %1, %29
%17 = phi i32 [ %35, %29 ], [ 0, %1 ]
%18 = call i32 @strlen(i8* %5)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %16, %20
%21 = phi i64 [ %25, %20 ], [ 0, %16 ]
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = call signext i8 @toupper(i8 signext %23)
store i8 %24, i8* %22
%25 = add nuw nsw i64 %21, 1
%26 = call i32 @strlen(i8* %5)
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %20, label %29
29: ; preds = %20, %16
%30 = load i32, i32* @stdout
%31 = load i32, i32* %4
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %31, i8* %5)
%33 = load i32, i32* @stdout
%34 = call i32 @fflush(i32 %33)
%35 = add nuw nsw i32 %17, 1
%36 = load i32, i32* %0
%37 = call i32 @read(i32 %36, i8* %6, i32 128)
%38 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %4, i8* %5)
%39 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %16
41: ; preds = %29, %1
%42 = phi i32 [ 0, %1 ], [ %35, %29 ]
%43 = call i32 @exit(i32 %42)
unreachable
}