#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 */
struct sigaction {
  int sa_flags;
  int /*<<< orphan*/ sa_mask;
  int /*<<< orphan*/ sa_handler;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int SA_NOCLDSTOP;
int SA_NOCLDWAIT;
int /*<<< orphan*/ SIGCLD;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int sigaction(int /*<<< orphan*/, struct sigaction *, int /*<<< orphan*/ *);
int sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ wait_msg(char *);
int main(void) {
  char *line = NULL;
  size_t line_size = 0;
  struct sigaction sa = {.sa_handler = SIG_IGN,
                         .sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT};
  if (-1 == sigemptyset(&sa.sa_mask)) {
    exit(EXIT_FAILURE);
  }
  if (-1 == sigaction(SIGCLD, &sa, NULL)) {
    exit(EXIT_FAILURE);
  }
  while (1) {
    printf("Alarm> ");
    if (-1 == getline(&line, &line_size, stdin)) {
      break;
    }
    switch (fork()) {
    case -1:
      goto main_exit;
    case 0:
      wait_msg(line);
    default:
      break;
    }
  }
main_exit:
  free(line);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    0x2e39(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
add    $0x4,%rdi
call   1070 <sigemptyset@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11f1 <main+0x71>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigaction@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1224 <main+0xa4>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1229 <main+0xa9>
lea    0xdd0(%rip),%rdi
call   1050 <printf@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    125f <main+0xdf>
jmp    12a1 <main+0x121>
xor    %eax,%eax
call   10a0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
sub    $0xffffffff,%eax
je     1289 <main+0x109>
jmp    1279 <main+0xf9>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
je     128e <main+0x10e>
jmp    1297 <main+0x117>
jmp    12a6 <main+0x126>
mov    -0x10(%rbp),%rdi
call   1060 <wait_msg@plt>
jmp    129c <main+0x11c>
jmp    1229 <main+0xa9>
jmp    12a6 <main+0x126>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x20(%rsp)
mov    0x2e24(%rip),%rax
mov    0x2e3d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x10(%rsp)
lea    0x14(%rsp),%rdi
movl   $0x0,0x14(%rsp)
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
call   1070 <sigemptyset@plt>
cmp    $0xffffffff,%eax
je     128e <main+0x10e>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1040 <sigaction@plt>
cmp    $0xffffffff,%eax
je     128e <main+0x10e>
lea    0xe00(%rip),%rdi
call   1050 <printf@plt>
mov    0x2dd4(%rip),%r12
mov    (%r12),%edx
lea    0x8(%rsp),%rdi
lea    0x20(%rsp),%rsi
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1276 <main+0xf6>
lea    0xdd5(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x20(%rsp),%rbx
jmp    1266 <main+0xe6>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
call   1060 <wait_msg@plt>
mov    %r14,%rdi
call   1050 <printf@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1276 <main+0xf6>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     1240 <main+0xc0>
cmp    $0xffffffff,%eax
jne    124a <main+0xca>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sigaction = type { i32, i32, i32 }
@SA_NOCLDSTOP = global i32 0
@SA_NOCLDWAIT = global i32 0
@SIG_IGN = global i32 0
@EXIT_FAILURE = global i32 0
@SIGCLD = global i32 0
@.str = [8 x i8] c"Alarm> \00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca %struct.sigaction
store i32 0, i32* %1
store i8* null, i8** %2
store i64 0, i64* %3
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i32 0, i32 0
%6 = load i32, i32* @SA_NOCLDSTOP
%7 = load i32, i32* @SA_NOCLDWAIT
%8 = or i32 %6, %7
store i32 %8, i32* %5
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i32 0, i32 1
store i32 0, i32* %9
%10 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i32 0, i32 2
%11 = load i32, i32* @SIG_IGN
store i32 %11, i32* %10
%12 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i32 0, i32 1
%13 = call i32 @sigemptyset(i32* %12)
%14 = icmp eq i32 -1, %13
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %0
%19 = load i32, i32* @SIGCLD
%20 = call i32 @sigaction(i32 %19, %struct.sigaction* %4, i32* null)
%21 = icmp eq i32 -1, %20
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %18
br label %26
26: ; preds = %25, %39
%27 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%28 = load i32, i32* @stdin
%29 = call i32 @getline(i8** %2, i64* %3, i32 %28)
%30 = icmp eq i32 -1, %29
br i1 %30, label %31, label %32
31: ; preds = %26
br label %40
32: ; preds = %26
%33 = call i32 (...) @fork()
switch i32 %33, label %38 [
i32 -1, label %34
i32 0, label %35
]
34: ; preds = %32
br label %41
35: ; preds = %32
%36 = load i8*, i8** %2
%37 = call i32 @wait_msg(i8* %36)
br label %38
38: ; preds = %32, %35
br label %39
39: ; preds = %38
br label %26
40: ; preds = %31
br label %41
41: ; preds = %40, %34
%42 = load i8*, i8** %2
%43 = call i32 @free(i8* %42)
ret i32 0
}

LLVM IR (-O2):
%struct.sigaction = type { i32, i32, i32 }
@SA_NOCLDSTOP = global i32 0
@SA_NOCLDWAIT = global i32 0
@SIG_IGN = global i32 0
@EXIT_FAILURE = global i32 0
@SIGCLD = global i32 0
@.str = [8 x i8] c"Alarm> \00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca %struct.sigaction
%4 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%5 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%6 = bitcast %struct.sigaction* %3 to i8*
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
%8 = load i32, i32* @SA_NOCLDSTOP
%9 = load i32, i32* @SA_NOCLDWAIT
%10 = or i32 %9, %8
store i32 %10, i32* %7
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
store i32 0, i32* %11
%12 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 2
%13 = load i32, i32* @SIG_IGN
store i32 %13, i32* %12
%14 = call i32 @sigemptyset(i32* %11)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %0
%20 = load i32, i32* @SIGCLD
%21 = call i32 @sigaction(i32 %20, %struct.sigaction* %3, i32* null)
%22 = icmp eq i32 %21, -1
br i1 %22, label %28, label %23
23: ; preds = %19
%24 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @stdin
%26 = call i32 @getline(i8** %1, i64* %2, i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %41, label %31
28: ; preds = %19
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %23, %36
%32 = call i32 (...) @fork()
switch i32 %32, label %36 [
i32 -1, label %41
i32 0, label %33
]
33: ; preds = %31
%34 = load i8*, i8** %1
%35 = call i32 @wait_msg(i8* %34)
br label %36
36: ; preds = %33, %31
%37 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%38 = load i32, i32* @stdin
%39 = call i32 @getline(i8** %1, i64* %2, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %31
41: ; preds = %31, %36, %23
%42 = load i8*, i8** %1
%43 = call i32 @free(i8* %42)
ret i32 0
}