#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 char pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ kill(char, int /*<<< orphan*/);
int /*<<< orphan*/ pause();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int strlen(char *);
char toupper(char);
int figlioConsumatore(void) {
  FILE *myfile;
  pid_t pidProduttore;
  char stringa[1024];
  int i;
  pause();
  if ((myfile = fopen("myfile.txt", "r")) == NULL) {
    fprintf(stderr, "Error file open.\n");
    return (-5);
  }
  fscanf(myfile, "%d", &pidProduttore);
  fclose(myfile);
  kill(pidProduttore, SIGUSR1);
  pause();
  while (1) {
    sleep(1);
    if ((myfile = fopen("myfile.txt", "r")) == NULL) {
      fprintf(stderr, "Error file open.\n");
      return (-6);
    }
    fscanf(myfile, "%s", stringa);
    for (i = 0; i < strlen(stringa); i++) {
      stringa[i] = toupper(stringa[i]);
    }
    fprintf(stdout, "%s\n", stringa);
    fclose(myfile);
    kill(pidProduttore, SIGUSR1);
    pause();
  }
  return 0;
}


x86 assembly (clang, -O0):
<figlioConsumatore>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    $0x0,%al
call   1090 <pause@plt>
lea    0xe57(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11e6 <figlioConsumatore+0x56>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xfffffffb,-0x4(%rbp)
jmp    1334 <figlioConsumatore+0x1a4>
mov    -0x10(%rbp),%rdi
lea    0xe2e(%rip),%rsi
lea    -0x11(%rbp),%rdx
call   1060 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x11(%rbp),%al
mov    0x2ddb(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1080 <kill@plt>
mov    $0x0,%al
call   1090 <pause@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xdd1(%rip),%rdi
lea    0xdd5(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    126c <figlioConsumatore+0xdc>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xfffffffa,-0x4(%rbp)
jmp    1334 <figlioConsumatore+0x1a4>
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xda4(%rip),%rsi
call   1060 <fscanf@plt>
movl   $0x0,-0x424(%rbp)
mov    -0x424(%rbp),%eax
mov    %eax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x428(%rbp),%eax
cmp    %ecx,%eax
jge    12ed <figlioConsumatore+0x15d>
movslq -0x424(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%edi
ff
call   1030 <toupper@plt>
mov    %al,%cl
movslq -0x424(%rbp),%rax
mov    %cl,-0x420(%rbp,%rax,1)
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    128d <figlioConsumatore+0xfd>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xd21(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x11(%rbp),%al
mov    0x2cca(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1080 <kill@plt>
mov    $0x0,%al
call   1090 <pause@plt>
jmp    121e <figlioConsumatore+0x8e>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<figlioConsumatore>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
xor    %eax,%eax
call   1090 <pause@plt>
lea    0xe51(%rip),%rdi
lea    0xe55(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1316 <figlioConsumatore+0x186>
mov    %rax,%rbx
lea    0xe51(%rip),%rsi
lea    0xf(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
movsbl 0xf(%rsp),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
call   1080 <kill@plt>
xor    %eax,%eax
call   1090 <pause@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xdf2(%rip),%rdi
lea    0xdf6(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12f8 <figlioConsumatore+0x168>
mov    %rax,%rbp
lea    0x10(%rsp),%rbx
lea    0xdf3(%rip),%r15
lea    0xdc7(%rip),%r12
lea    0xdcb(%rip),%r13
jmp    12a5 <figlioConsumatore+0x115>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
movsbl 0xf(%rsp),%edi
mov    0x2d6e(%rip),%rax
mov    (%rax),%esi
call   1080 <kill@plt>
xor    %eax,%eax
call   1090 <pause@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12f8 <figlioConsumatore+0x168>
mov    %rbp,%rdi
lea    0xd73(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fscanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1250 <figlioConsumatore+0xc0>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
movsbl 0x10(%rsp,%r14,1),%edi
call   1030 <toupper@plt>
mov    %al,0x10(%rsp,%r14,1)
add    $0x1,%r14
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%r14
jl     12d0 <figlioConsumatore+0x140>
jmp    1250 <figlioConsumatore+0xc0>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
lea    0xd05(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xfffffffa,%eax
jmp    1332 <figlioConsumatore+0x1a2>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
lea    0xce7(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xfffffffb,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"myfile.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"Error file open.\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@SIGUSR1 = global i32 0
@.str.4 = [3 x i8] c"%s\00"
@stdout = global i32 0
@.str.5 = [4 x i8] c"%s\0A\00"
define i32 @figlioConsumatore() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = call i32 (...) @pause()
%7 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 -5, i32* %1
br label %59
12: ; preds = %0
%13 = load i32*, i32** %2
%14 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%15 = load i32*, i32** %2
%16 = call i32 @fclose(i32* %15)
%17 = load i8, i8* %3
%18 = load i32, i32* @SIGUSR1
%19 = call i32 @kill(i8 signext %17, i32 %18)
%20 = call i32 (...) @pause()
br label %21
21: ; preds = %12, %49
%22 = call i32 @sleep(i32 1)
%23 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %2
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 -6, i32* %1
br label %59
28: ; preds = %21
%29 = load i32*, i32** %2
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%31 = call i32 @fscanf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %30)
store i32 0, i32* %5
br label %32
32: ; preds = %46, %28
%33 = load i32, i32* %5
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %49
37: ; preds = %32
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = call signext i8 @toupper(i8 signext %41)
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %44
store i8 %42, i8* %45
br label %46
46: ; preds = %37
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
store i32 %48, i32* %5
br label %32
49: ; preds = %32
%50 = load i32, i32* @stdout
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %51)
%53 = load i32*, i32** %2
%54 = call i32 @fclose(i32* %53)
%55 = load i8, i8* %3
%56 = load i32, i32* @SIGUSR1
%57 = call i32 @kill(i8 signext %55, i32 %56)
%58 = call i32 (...) @pause()
br label %21
59: ; preds = %25, %9
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
@.str = [11 x i8] c"myfile.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"Error file open.\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@SIGUSR1 = global i32 0
@.str.4 = [3 x i8] c"%s\00"
@stdout = global i32 0
@.str.5 = [4 x i8] c"%s\0A\00"
define i32 @figlioConsumatore() {
%1 = alloca i8
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (...) @pause()
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %48
10: ; preds = %0
%11 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%12 = call i32 @fclose(i32* %5)
%13 = load i8, i8* %1
%14 = load i32, i32* @SIGUSR1
%15 = call i32 @kill(i8 signext %13, i32 %14)
%16 = call i32 (...) @pause()
%17 = call i32 @sleep(i32 1)
%18 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %37, %10
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %48
23: ; preds = %10, %37
%24 = phi i32* [ %46, %37 ], [ %18, %10 ]
%25 = call i32 @fscanf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%26 = call i32 @strlen(i8* %3)
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %23, %28
%29 = phi i64 [ %33, %28 ], [ 0, %23 ]
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = call signext i8 @toupper(i8 signext %31)
store i8 %32, i8* %30
%33 = add nuw nsw i64 %29, 1
%34 = call i32 @strlen(i8* %3)
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %33, %35
br i1 %36, label %28, label %37
37: ; preds = %28, %23
%38 = load i32, i32* @stdout
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%40 = call i32 @fclose(i32* %24)
%41 = load i8, i8* %1
%42 = load i32, i32* @SIGUSR1
%43 = call i32 @kill(i8 signext %41, i32 %42)
%44 = call i32 (...) @pause()
%45 = call i32 @sleep(i32 1)
%46 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%47 = icmp eq i32* %46, null
br i1 %47, label %20, label %23
48: ; preds = %20, %7
%49 = phi i32 [ -5, %7 ], [ -6, %20 ]
ret i32 %49
}