#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);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/, char *, char *);
int getpid();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
void figlioProduttore(pid_t pidConsumatore, int fd[2]) {
  char line[128], tmp[128];
  pid_t pidProduttore;
  int msgProd = 0;
  close(fd[0]);
  pidProduttore = getpid();
  while (1) {
    fprintf(stdout, "Produttore (pidConsumatore=%d): ", pidConsumatore);
    fflush(stdout);
    fscanf(stdin, "%s", line);
    sprintf(tmp, "%5d%s", pidProduttore, line);
    write(fd[1], tmp, (strlen(tmp) + 1));
    msgProd++;
    if (strcmp(line, "end") == 0)
      break;
    sleep(1);
  }
  exit(msgProd);
}


x86 assembly (clang, -O0):
<figlioProduttore>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x118(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1070 <close@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x114(%rbp)
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe09(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    -0x90(%rbp),%rdx
lea    0xe03(%rip),%rsi
call   1060 <fscanf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x114(%rbp),%edx
lea    -0x90(%rbp),%rcx
lea    0xde0(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x124(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x124(%rbp),%edi
mov    -0x120(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xd84(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12b7 <figlioProduttore+0x107>
jmp    12c6 <figlioProduttore+0x116>
mov    $0x1,%edi
call   10d0 <sleep@plt>
jmp    11e4 <figlioProduttore+0x34>
mov    -0x118(%rbp),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<figlioProduttore>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %edi,0x4(%rsp)
mov    %rsi,0x8(%rsp)
mov    (%rsi),%edi
call   1070 <close@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebp
mov    $0x1,%ebx
mov    0x2df2(%rip),%r15
lea    0x90(%rsp),%r12
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%edi
lea    0xdf6(%rip),%rsi
mov    0x4(%rsp),%edx
call   1090 <fprintf@plt>
mov    (%r15),%edi
call   10a0 <fflush@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
mov    %r12,%rdx
call   1060 <fscanf@plt>
mov    %r13,%rdi
lea    0xde4(%rip),%rsi
mov    %ebp,%edx
mov    %r12,%rcx
call   10b0 <sprintf@plt>
mov    0x8(%rsp),%rax
mov    0x4(%rax),%r14d
mov    %r13,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14d,%edi
mov    %r13,%rsi
call   1030 <write@plt>
mov    %r12,%rdi
lea    0xdb6(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     128d <figlioProduttore+0xdd>
mov    $0x1,%edi
call   10d0 <sleep@plt>
add    $0x1,%ebx
jmp    1200 <figlioProduttore+0x50>
mov    %ebx,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [33 x i8] c"Produttore (pidConsumatore=%d): \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [6 x i8] c"%5d%s\00"
@.str.3 = [4 x i8] c"end\00"
define void @figlioProduttore(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [128 x i8]
%6 = alloca [128 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
store i32 0, i32* %8
%9 = load i32*, i32** %4
%10 = getelementptr inbounds i32, i32* %9, i64 0
%11 = load i32, i32* %10
%12 = call i32 @close(i32 %11)
%13 = call i32 (...) @getpid()
store i32 %13, i32* %7
br label %14
14: ; preds = %2, %41
%15 = load i32, i32* @stdout
%16 = load i32, i32* %3
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i32, i32* @stdout
%19 = call i32 @fflush(i32 %18)
%20 = load i32, i32* @stdin
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%22 = call i32 @fscanf(i32 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%24 = load i32, i32* %7
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%26 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %24, i8* %25)
%27 = load i32*, i32** %4
%28 = getelementptr inbounds i32, i32* %27, i64 1
%29 = load i32, i32* %28
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%32 = call i64 @strlen(i8* %31)
%33 = add nsw i64 %32, 1
%34 = call i32 @write(i32 %29, i8* %30, i64 %33)
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %14
br label %43
41: ; preds = %14
%42 = call i32 @sleep(i32 1)
br label %14
43: ; preds = %40
%44 = load i32, i32* %8
%45 = call i32 @exit(i32 %44)
unreachable
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [33 x i8] c"Produttore (pidConsumatore=%d): \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [6 x i8] c"%5d%s\00"
@.str.3 = [4 x i8] c"end\00"
define void @figlioProduttore(i32 %0, i32* nocapture %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* %1
%8 = tail call i32 @close(i32 %7)
%9 = tail call i32 (...) @getpid()
%10 = getelementptr inbounds i32, i32* %1, i64 1
br label %11
11: ; preds = %27, %2
%12 = phi i32 [ 0, %2 ], [ %24, %27 ]
%13 = load i32, i32* @stdout
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %0)
%15 = load i32, i32* @stdout
%16 = call i32 @fflush(i32 %15)
%17 = load i32, i32* @stdin
%18 = call i32 @fscanf(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%19 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %9, i8* %5)
%20 = load i32, i32* %10
%21 = call i64 @strlen(i8* %6)
%22 = add nsw i64 %21, 1
%23 = call i32 @write(i32 %20, i8* %6, i64 %22)
%24 = add nuw nsw i32 %12, 1
%25 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %11
%28 = call i32 @sleep(i32 1)
br label %11
29: ; preds = %11
%30 = call i32 @exit(i32 %24)
unreachable
}