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

/* Variables and functions */
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ childprocess(char *);
scalar_t__ fork();
int /*<<< orphan*/ kill(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  pid_t id;
  int number;
  id = fork();
  if (id == 0) {
    childprocess("Enter a number");
    return 0;
  }
  while (1) {
    scanf("%d", &number);
    if (number == 123)
      break;
    printf("Try again\n");
  }
  kill(id, SIGUSR1);
  printf("Finally!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118d <main+0x3d>
lea    0xe84(%rip),%rdi
call   1050 <childprocess@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <main+0x97>
jmp    1192 <main+0x42>
lea    0xe76(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x7b,-0x14(%rbp)
jne    11b1 <main+0x61>
jmp    11c2 <main+0x72>
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
jmp    1192 <main+0x42>
mov    -0x10(%rbp),%rdi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     11d9 <main+0x89>
mov    %rax,%r14
lea    0xea1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
cmpl   $0x7b,0x4(%rsp)
je     11ba <main+0x6a>
lea    0xe8c(%rip),%r15
lea    0xe82(%rip),%r12
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
cmpl   $0x7b,0x4(%rsp)
jne    11a0 <main+0x50>
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1040 <kill@plt>
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
jmp    11e5 <main+0x95>
lea    0xe20(%rip),%rdi
call   1050 <childprocess@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Enter a number\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"Try again\0A\00"
@SIGUSR1 = global i32 0
@.str.3 = [10 x i8] c"Finally!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 (...) @fork()
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @childprocess(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %22
9: ; preds = %0
br label %10
10: ; preds = %9, %15
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 123
br i1 %13, label %14, label %15
14: ; preds = %10
br label %17
15: ; preds = %10
%16 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %10
17: ; preds = %14
%18 = load i64, i64* %2
%19 = load i32, i32* @SIGUSR1
%20 = call i32 @kill(i64 %18, i32 %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %22
22: ; preds = %17, %7
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [15 x i8] c"Enter a number\00"
@.str.1 = [3 x i8] c"%d\00"
@SIGUSR1 = global i32 0
@str = [10 x i8] c"Try again\00"
@str.4 = [9 x i8] c"Finally!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 123
br i1 %8, label %16, label %11
9: ; preds = %0
%10 = tail call i32 @childprocess(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %20
11: ; preds = %5, %11
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 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* %1)
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, 123
br i1 %15, label %16, label %11
16: ; preds = %11, %5
%17 = load i32, i32* @SIGUSR1
%18 = call i32 @kill(i64 %3, i32 %17)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.4, i64 0, i64 0))
br label %20
20: ; preds = %16, %9
ret i32 0
}