#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*/ 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: ");
    if (scanf("%d", &x) != 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    $0x30,%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    0xe3f(%rip),%rdi
call   1060 <printf@plt>
lea    0xe46(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   10a0 <scanf@plt>
cmp    $0x1,%eax
je     122c <pere+0x9c>
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %eax,%ecx
lea    0xe0c(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1227 <pere+0x97>
jmp    120f <pere+0x7f>
jmp    11ba <pere+0x2a>
cmpl   $0x0,-0x1c(%rbp)
jl     1249 <pere+0xb9>
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     1266 <pere+0xd6>
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    1275 <pere+0xe5>
jmp    127a <pere+0xea>
jmp    11ba <pere+0x2a>
xor    %edi,%edi
call   1090 <waitendverbose@plt>
xor    %edi,%edi
call   1090 <waitendverbose@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<pere>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x2,%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
lea    0xe41(%rip),%r13
lea    0xe4d(%rip),%rbx
lea    0xc(%rsp),%rbp
jmp    11f0 <pere+0x60>
nopl   (%rax)
mov    0x10(%rsp),%rax
mov    0x4(%rax),%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmpl   $0x0,0xc(%rsp)
je     1270 <pere+0xe0>
mov    %r13,%rdi
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10a0 <scanf@plt>
cmp    $0x1,%eax
jne    1230 <pere+0xa0>
cmpl   $0x0,0xc(%rsp)
js     11d0 <pere+0x40>
mov    0x4(%r15),%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmpl   $0x0,0xc(%rsp)
jg     11f0 <pere+0x60>
jmp    11d0 <pere+0x40>
nopl   0x0(%rax)
mov    0x2da9(%rip),%rax
mov    (%rax),%r14d
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %r14d,%edi
lea    0xdcb(%rip),%rsi
mov    %r12,%rdx
mov    %eax,%ecx
call   1080 <fprintf@plt>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
jne    1260 <pere+0xd0>
jmp    11f0 <pere+0x60>
xor    %edi,%edi
call   1090 <waitendverbose@plt>
xor    %edi,%edi
call   1090 <waitendverbose@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"entrez un entier: \00"
@.str.1 = [3 x i8] c"%d\00"
@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
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 4, i32* %8
%9 = call i32 @dup2(i32 2, i32 1)
br label %10
10: ; preds = %3, %24, %47
%11 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %4
%17 = call i32 (...) @getpid()
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %16, i32 %17)
br label %19
19: ; preds = %23, %14
%20 = call signext i8 (...) @getchar()
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %19
br label %19
24: ; preds = %19
br label %10
25: ; preds = %10
%26 = load i32, i32* %7
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i32*, i32** %5
%30 = getelementptr inbounds i32, i32* %29, i64 1
%31 = load i32, i32* %30
%32 = load i32, i32* %8
%33 = call i32 @write(i32 %31, i32* %7, i32 %32)
br label %34
34: ; preds = %28, %25
%35 = load i32, i32* %7
%36 = icmp sle i32 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = load i32*, i32** %6
%39 = getelementptr inbounds i32, i32* %38, i64 1
%40 = load i32, i32* %39
%41 = load i32, i32* %8
%42 = call i32 @write(i32 %40, i32* %7, i32 %41)
br label %43
43: ; preds = %37, %34
%44 = load i32, i32* %7
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %43
br label %48
47: ; preds = %43
br label %10
48: ; preds = %46
%49 = call i32 @waitendverbose(i32 0)
%50 = call i32 @waitendverbose(i32 0)
%51 = 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"
@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
br label %9
9: ; preds = %28, %3
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%12 = icmp eq i32 %11, 1
br i1 %12, label %20, label %13
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = call i32 (...) @getpid()
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %15)
br label %17
17: ; preds = %17, %13
%18 = call signext i8 (...) @getchar()
%19 = icmp eq i8 %18, 10
br i1 %19, label %28, label %17
20: ; preds = %9
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, -1
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i32, i32* %7
%25 = call i32 @write(i32 %24, i32* %4, i32 4)
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 1
br i1 %27, label %29, label %28
28: ; preds = %17, %23, %29
br label %9
29: ; preds = %23, %20
%30 = load i32, i32* %8
%31 = call i32 @write(i32 %30, i32* %4, i32 4)
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %28
34: ; preds = %29
%35 = call i32 @waitendverbose(i32 0)
%36 = call i32 @waitendverbose(i32 0)
%37 = call i32 @exit(i32 0)
unreachable
}