#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*/ exit(int);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ print_help();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_exit_message(char *);
int /*<<< orphan*/ set_login_message(char *);
int /*<<< orphan*/ set_prompt(char *);
int /*<<< orphan*/ stdin;
char *strtok(char *, char *);
void loop() {
  char buf[1024];
  while (true) {
    printf("Config action: ");
    char *result = fgets(buf, 1024, stdin);
    if (!result)
      exit(1);
    char *type = strtok(result, " ");
    if (type == NULL) {
      continue;
    }
    char *arg = strtok(NULL, "\n");
    switch (type[0]) {
    case 'l':
      set_login_message(arg);
      break;
    case 'e':
      set_exit_message(arg);
      break;
    case 'p':
      set_prompt(arg);
      break;
    default:
      printf("Command unrecognized.\n");
    case 'h':
      print_help();
      break;
    }
  }
}


x86 assembly (clang, -O0):
<loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
lea    0xe9e(%rip),%rdi
call   1040 <printf@plt>
lea    -0x400(%rbp),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    %rax,-0x408(%rbp)
cmpq   $0x0,-0x408(%rbp)
jne    11d0 <loop+0x50>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x408(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x410(%rbp)
cmpq   $0x0,-0x410(%rbp)
jne    11fd <loop+0x7d>
jmp    118b <loop+0xb>
lea    0xe51(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1080 <strtok@plt>
mov    %rax,-0x418(%rbp)
mov    -0x410(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffff9b,%eax
mov    %eax,%ecx
mov    %rcx,-0x420(%rbp)
sub    $0xb,%eax
ja     127d <loop+0xfd>
mov    -0x420(%rbp),%rax
lea    0xdbf(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x418(%rbp),%rdi
call   1030 <set_login_message@plt>
jmp    1290 <loop+0x110>
mov    -0x418(%rbp),%rdi
call   1050 <set_exit_message@plt>
jmp    1290 <loop+0x110>
mov    -0x418(%rbp),%rdi
call   1070 <set_prompt@plt>
jmp    1290 <loop+0x110>
lea    0xdbc(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1090 <print_help@plt>
jmp    118b <loop+0xb>

x86 assembly (clang, -O2):
<loop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
lea    0xe88(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e34(%rip),%r13
mov    0x0(%r13),%edx
mov    %rsp,%rdi
mov    $0x400,%esi
call   1070 <fgets@plt>
test   %rax,%rax
jne    11d4 <loop+0x44>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xe63(%rip),%r14
lea    0xe4e(%rip),%r15
mov    %rsp,%rbx
lea    0xe14(%rip),%r12
jmp    121f <loop+0x8f>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10a0 <print_help@plt>
mov    %r15,%rdi
call   1050 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     11ca <loop+0x3a>
mov    %rax,%rdi
mov    %r14,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
je     1201 <loop+0x71>
mov    %rax,%rbp
xor    %edi,%edi
lea    0xe05(%rip),%rsi
call   1090 <strtok@plt>
movsbl 0x0(%rbp),%ecx
add    $0xffffff9b,%ecx
cmp    $0xb,%ecx
ja     11ee <loop+0x5e>
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
mov    %rax,%rdi
call   1060 <set_exit_message@plt>
jmp    1201 <loop+0x71>
mov    %rax,%rdi
call   1040 <set_login_message@plt>
jmp    1201 <loop+0x71>
mov    %rax,%rdi
call   1080 <set_prompt@plt>
jmp    1201 <loop+0x71>

LLVM IR (-O0):
@.str = [16 x i8] c"Config action: \00"
@stdin = global i32 0
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [23 x i8] c"Command unrecognized.\0A\00"
define void @loop() {
%1 = alloca [1024 x i8]
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
br label %5
5: ; preds = %0, %19, %39
%6 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i8* @fgets(i8* %7, i32 1024, i32 %8)
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = icmp ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %5
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %5
%15 = load i8*, i8** %2
%16 = call i8* @strtok(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %14
br label %5
20: ; preds = %14
%21 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %21, i8** %4
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
switch i32 %25, label %35 [
i32 108, label %26
i32 101, label %29
i32 112, label %32
i32 104, label %37
]
26: ; preds = %20
%27 = load i8*, i8** %4
%28 = call i32 @set_login_message(i8* %27)
br label %39
29: ; preds = %20
%30 = load i8*, i8** %4
%31 = call i32 @set_exit_message(i8* %30)
br label %39
32: ; preds = %20
%33 = load i8*, i8** %4
%34 = call i32 @set_prompt(i8* %33)
br label %39
35: ; preds = %20
%36 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %20, %35
%38 = call i32 (...) @print_help()
br label %39
39: ; preds = %37, %32, %29, %26
br label %5
}

LLVM IR (-O2):
@.str = [16 x i8] c"Config action: \00"
@stdin = global i32 0
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"\0A\00"
@str = [22 x i8] c"Command unrecognized.\00"
define void @loop() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i8* @fgets(i8* %2, i32 1024, i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %27, %0
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0, %27
%10 = phi i8* [ %30, %27 ], [ %5, %0 ]
%11 = call i8* @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %27, label %13
13: ; preds = %9
%14 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = load i8, i8* %11
%16 = sext i8 %15 to i32
switch i32 %16, label %23 [
i32 108, label %17
i32 101, label %19
i32 112, label %21
i32 104, label %25
]
17: ; preds = %13
%18 = call i32 @set_login_message(i8* %14)
br label %27
19: ; preds = %13
%20 = call i32 @set_exit_message(i8* %14)
br label %27
21: ; preds = %13
%22 = call i32 @set_prompt(i8* %14)
br label %27
23: ; preds = %13
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %25
25: ; preds = %13, %23
%26 = call i32 (...) @print_help()
br label %27
27: ; preds = %17, %19, %21, %25, %9
%28 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* @stdin
%30 = call i8* @fgets(i8* %2, i32 1024, i32 %29)
%31 = icmp eq i8* %30, null
br i1 %31, label %7, label %9
}