#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 EOF;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
char getchar();
int getpid();
int /*<<< orphan*/ printf(char *);
int scanf(char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ waitendverbose(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, int *, int);
void pere(char *nickname, int pos[2], int neg[2]) {
  int x;
  int len = sizeof x;
  dup2(2, 1);
  while (1) {
    printf("entrez un entier: ");
    int r = scanf("%d", &x);
    if (r == EOF) {
      close(pos[1]);
      close(neg[1]);
      break;
    } else if (r != 1) {
      fprintf(stderr, "%s:%d: probleme lecture stdin.\n", nickname, getpid());
      while (getchar() != '\n')
        ;
      continue;
    }
    if (x >= 0)
      write(pos[1], &x, len);
    if (x <= 0)
      write(neg[1], &x, len);
    if (x == 0)
      break;
  }
  waitendverbose(0);
  waitendverbose(0);
  exit(0);
}


x86 assembly (clang, -O0):
<pere>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x4,-0x20(%rbp)
mov    $0x2,%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
lea    0xe2f(%rip),%rdi
call   1060 <printf@plt>
lea    0xe36(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   10b0 <scanf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2df5(%rip),%rcx
cmp    (%rcx),%eax
jne    1218 <pere+0x78>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
call   1070 <close@plt>
jmp    12c2 <pere+0x122>
cmpl   $0x1,-0x24(%rbp)
je     126f <pere+0xcf>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
lea    0xdc9(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     126a <pere+0xca>
jmp    1252 <pere+0xb2>
jmp    11ca <pere+0x2a>
jmp    1274 <pere+0xd4>
cmpl   $0x0,-0x1c(%rbp)
jl     1291 <pere+0xf1>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x20(%rbp),%edx
lea    -0x1c(%rbp),%rsi
call   1030 <write@plt>
cmpl   $0x0,-0x1c(%rbp)
jg     12ae <pere+0x10e>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x20(%rbp),%edx
lea    -0x1c(%rbp),%rsi
call   1030 <write@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    12bd <pere+0x11d>
jmp    12c2 <pere+0x122>
jmp    11ca <pere+0x2a>
xor    %edi,%edi
call   10a0 <waitendverbose@plt>
xor    %edi,%edi
call   10a0 <waitendverbose@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<pere>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x8(%rsp)
mov    %rsi,0x10(%rsp)
mov    %rdi,%r12
mov    $0x2,%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
lea    0xe2f(%rip),%rdi
call   1060 <printf@plt>
lea    0xe36(%rip),%rdi
lea    0x4(%rsp),%rsi
call   10b0 <scanf@plt>
mov    0x2dfa(%rip),%r14
cmp    (%r14),%eax
jne    1222 <pere+0x82>
mov    0x10(%rsp),%rax
mov    0x4(%rax),%edi
call   1070 <close@plt>
mov    0x8(%rsp),%rax
mov    0x4(%rax),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10a0 <waitendverbose@plt>
xor    %edi,%edi
call   10a0 <waitendverbose@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0x4(%rsp),%rbx
lea    0xdd2(%rip),%r13
lea    0xdde(%rip),%rbp
jmp    1278 <pere+0xd8>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
mov    0x4(%rax),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmpl   $0x0,0x4(%rsp)
je     120d <pere+0x6d>
mov    %r13,%rdi
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
cmp    (%r14),%eax
je     11f3 <pere+0x53>
cmp    $0x1,%eax
jne    12b0 <pere+0x110>
cmpl   $0x0,0x4(%rsp)
js     1240 <pere+0xa0>
mov    0x10(%rsp),%rax
mov    0x4(%rax),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmpl   $0x0,0x4(%rsp)
jg     125c <pere+0xbc>
jmp    1240 <pere+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2d21(%rip),%rax
mov    (%rax),%r15d
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %r15d,%edi
lea    0xd4b(%rip),%rsi
mov    %r12,%rdx
mov    %eax,%ecx
call   1090 <fprintf@plt>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1080 <getchar@plt>
cmp    $0xa,%al
jne    12e0 <pere+0x140>
jmp    125c <pere+0xbc>

LLVM IR (-O0):
@.str = [19 x i8] c"entrez un entier: \00"
@.str.1 = [3 x i8] c"%d\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.2 = [32 x i8] c"%s:%d: probleme lecture stdin.\0A\00"
define void @pere(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 4, i32* %8
%10 = call i32 @dup2(i32 2, i32 1)
br label %11
11: ; preds = %3, %39, %63
%12 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %26
17: ; preds = %11
%18 = load i32*, i32** %5
%19 = getelementptr inbounds i32, i32* %18, i64 1
%20 = load i32, i32* %19
%21 = call i32 @close(i32 %20)
%22 = load i32*, i32** %6
%23 = getelementptr inbounds i32, i32* %22, i64 1
%24 = load i32, i32* %23
%25 = call i32 @close(i32 %24)
br label %64
26: ; preds = %11
%27 = load i32, i32* %9
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %40
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %4
%32 = call i32 (...) @getpid()
%33 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %31, i32 %32)
br label %34
34: ; preds = %38, %29
%35 = call signext i8 (...) @getchar()
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 10
br i1 %37, label %38, label %39
38: ; preds = %34
br label %34
39: ; preds = %34
br label %11
40: ; preds = %26
br label %41
41: ; preds = %40
%42 = load i32, i32* %7
%43 = icmp sge i32 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %41
%45 = load i32*, i32** %5
%46 = getelementptr inbounds i32, i32* %45, i64 1
%47 = load i32, i32* %46
%48 = load i32, i32* %8
%49 = call i32 @write(i32 %47, i32* %7, i32 %48)
br label %50
50: ; preds = %44, %41
%51 = load i32, i32* %7
%52 = icmp sle i32 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %50
%54 = load i32*, i32** %6
%55 = getelementptr inbounds i32, i32* %54, i64 1
%56 = load i32, i32* %55
%57 = load i32, i32* %8
%58 = call i32 @write(i32 %56, i32* %7, i32 %57)
br label %59
59: ; preds = %53, %50
%60 = load i32, i32* %7
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %59
br label %64
63: ; preds = %59
br label %11
64: ; preds = %62, %17
%65 = call i32 @waitendverbose(i32 0)
%66 = call i32 @waitendverbose(i32 0)
%67 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [19 x i8] c"entrez un entier: \00"
@.str.1 = [3 x i8] c"%d\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.2 = [32 x i8] c"%s:%d: probleme lecture stdin.\0A\00"
define void @pere(i8* %0, i32* nocapture %1, i32* nocapture %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 @dup2(i32 2, i32 1)
%7 = getelementptr inbounds i32, i32* %1, i64 1
%8 = getelementptr inbounds i32, i32* %2, i64 1
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %18
13: ; preds = %41, %3
%14 = load i32, i32* %7
%15 = call i32 @close(i32 %14)
%16 = load i32, i32* %8
%17 = call i32 @close(i32 %16)
br label %46
18: ; preds = %3, %41
%19 = phi i32 [ %43, %41 ], [ %10, %3 ]
%20 = icmp eq i32 %19, 1
br i1 %20, label %28, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 (...) @getpid()
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %23)
br label %25
25: ; preds = %25, %21
%26 = call signext i8 (...) @getchar()
%27 = icmp eq i8 %26, 10
br i1 %27, label %41, label %25
28: ; preds = %18
%29 = load i32, i32* %4
%30 = icmp sgt i32 %29, -1
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load i32, i32* %7
%33 = call i32 @write(i32 %32, i32* %4, i32 4)
%34 = load i32, i32* %4
%35 = icmp slt i32 %34, 1
br i1 %35, label %36, label %41
36: ; preds = %31, %28
%37 = load i32, i32* %8
%38 = call i32 @write(i32 %37, i32* %4, i32 4)
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, 0
br i1 %40, label %46, label %41
41: ; preds = %25, %31, %36
%42 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%43 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%44 = load i32, i32* @EOF
%45 = icmp eq i32 %43, %44
br i1 %45, label %13, label %18
46: ; preds = %36, %13
%47 = call i32 @waitendverbose(i32 0)
%48 = call i32 @waitendverbose(i32 0)
%49 = call i32 @exit(i32 0)
unreachable
}