#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_FAILURE;
int /*<<< orphan*/ execve(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strncmp(char *, char *, int);
int main(int argc, char *argv[]) {
  char program[] = "/usr/local/sbin/message";
  char buf[20];
  char authorized[] = "Simon";
  printf("What is your name?\n");
  gets(buf);
  if (!strncmp(authorized, buf, 3)) {
    printf("Hello %s! Here is your message:\n\n", buf);
    execve(program, NULL, NULL);
  } else {
    printf("Sorry %s, you're not %s! The Internet Police have been informed of "
           "this violation.\n",
           buf, authorized);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe97(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe94(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe92(%rip),%eax
mov    %eax,-0x56(%rbp)
mov    0xe8c(%rip),%ax
mov    %ax,-0x52(%rbp)
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
call   1060 <gets@plt>
lea    -0x56(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11ed <main+0x9d>
lea    -0x50(%rbp),%rsi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1050 <execve@plt>
jmp    1211 <main+0xc1>
lea    -0x50(%rbp),%rsi
lea    -0x56(%rbp),%rdx
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
movaps 0xe94(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movabs $0x6567617373656d,%rax
mov    %rax,0x40(%rsp)
movw   $0x6e,0xc(%rsp)
movl   $0x6f6d6953,0x8(%rsp)
6f
lea    0xefe(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <gets@plt>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11e7 <main+0x87>
lea    0xe59(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x30(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <execve@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
ret
lea    0xe52(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@__const.main.program = [24 x i8] c"/usr/local/sbin/message\00"
@__const.main.authorized = [6 x i8] c"Simon\00"
@.str = [20 x i8] c"What is your name?\0A\00"
@.str.1 = [34 x i8] c"Hello %s! Here is your message:\0A\0A\00"
@.str.2 = [84 x i8] c"Sorry %s, you're not %s! The Internet Police have been informed of this violation.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [24 x i8]
%6 = alloca [20 x i8]
%7 = alloca [6 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = bitcast [24 x i8]* %5 to i8*
%9 = bitcast [6 x i8]* %7 to i8*
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%12 = call i32 @gets(i8* %11)
%13 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%15 = call i32 @strncmp(i8* %13, i8* %14, i32 3)
%16 = icmp ne i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %2
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [24 x i8], [24 x i8]* %5, i64 0, i64 0
%21 = call i32 @execve(i8* %20, i32* null, i32* null)
br label %28
22: ; preds = %2
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%24 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %17
ret i32 0
}

LLVM IR (-O2):
@__const.main.program = [24 x i8] c"/usr/local/sbin/message\00"
@__const.main.authorized = [6 x i8] c"Simon\00"
@.str.1 = [34 x i8] c"Hello %s! Here is your message:\0A\0A\00"
@.str.2 = [84 x i8] c"Sorry %s, you're not %s! The Internet Police have been informed of this violation.\0A\00"
@EXIT_FAILURE = global i32 0
@str = [19 x i8] c"What is your name?\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [24 x i8]
%4 = alloca [20 x i8]
%5 = alloca [6 x i8]
%6 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%10 = call i32 @gets(i8* %7)
%11 = call i32 @strncmp(i8* %8, i8* %7, i32 3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%15 = call i32 @execve(i8* %6, i32* null, i32* null)
ret i32 0
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([84 x i8], [84 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %8)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
}