#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);
int /*<<< orphan*/ printf(char *, ...);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int main(int argc, char *argv[]) {
  char serial[256];
  if (argc != 2) {
    printf("Usage: %s <serial>\n", argv[0]);
    exit(1);
  }
  size_t serial_len = strlen(argv[1]);
  if (256 <= serial_len) {
    printf("[-] Serial too long.\n");
    exit(1);
  }
  if (3 > serial_len) {
    printf("[-] Serial too short.\n");
    exit(1);
  }
  strncpy(serial, argv[1], serial_len);
  if (serial[0] != 's') {
    return 0;
  }
  if (serial[1] != 'e') {
    return 0;
  }
  if (serial[2] != 'r') {
    return 0;
  }
  printf("Serial's fine!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1182 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x118(%rbp)
mov    $0x100,%eax
cmp    -0x118(%rbp),%rax
ja     11c0 <main+0x80>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    $0x3,%eax
cmp    -0x118(%rbp),%rax
jbe    11ea <main+0xaa>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x118(%rbp),%rdx
call   1030 <strncpy@plt>
movsbl -0x110(%rbp),%eax
cmp    $0x73,%eax
je     1221 <main+0xe1>
movl   $0x0,-0x4(%rbp)
jmp    126e <main+0x12e>
movsbl -0x10f(%rbp),%eax
cmp    $0x65,%eax
je     123d <main+0xfd>
movl   $0x0,-0x4(%rbp)
jmp    126e <main+0x12e>
movsbl -0x10e(%rbp),%eax
cmp    $0x72,%eax
je     1259 <main+0x119>
movl   $0x0,-0x4(%rbp)
jmp    126e <main+0x12e>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100,%rsp
cmp    $0x2,%edi
jne    11b0 <main+0x60>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x100,%rax
jae    11cb <main+0x7b>
cmp    $0x2,%rax
jbe    11d4 <main+0x84>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <strncpy@plt>
cmpb   $0x73,(%rsp)
jne    11a5 <main+0x55>
cmpb   $0x65,0x1(%rsp)
jne    11a5 <main+0x55>
cmpb   $0x72,0x2(%rsp)
jne    11a5 <main+0x55>
lea    0xe74(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
ret
mov    (%rsi),%rsi
lea    0xe46(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe67(%rip),%rdi
jmp    11db <main+0x8b>
lea    0xe48(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Usage: %s <serial>\0A\00"
@.str.1 = [22 x i8] c"[-] Serial too long.\0A\00"
@.str.2 = [23 x i8] c"[-] Serial too short.\0A\00"
@.str.3 = [16 x i8] c"Serial's fine!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strlen(i8* %19)
store i64 %20, i64* %7
%21 = load i64, i64* %7
%22 = icmp ule i64 256, %21
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %16
%27 = load i64, i64* %7
%28 = icmp ugt i64 3, %27
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %26
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i64, i64* %7
%38 = call i32 @strncpy(i8* %33, i8* %36, i64 %37)
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 115
br i1 %42, label %43, label %44
43: ; preds = %32
store i32 0, i32* %3
br label %58
44: ; preds = %32
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 1
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 101
br i1 %48, label %49, label %50
49: ; preds = %44
store i32 0, i32* %3
br label %58
50: ; preds = %44
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 2
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 114
br i1 %54, label %55, label %56
55: ; preds = %50
store i32 0, i32* %3
br label %58
56: ; preds = %50
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %58
58: ; preds = %56, %55, %49, %43
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [20 x i8] c"Usage: %s <serial>\0A\00"
@str = [15 x i8] c"Serial's fine!\00"
@str.4 = [22 x i8] c"[-] Serial too short.\00"
@str.5 = [21 x i8] c"[-] Serial too long.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strlen(i8* dereferenceable(1) %12)
%14 = icmp ugt i64 %13, 255
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = icmp ult i64 %13, 3
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.4, i64 0, i64 0))
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %18
%24 = call i32 @strncpy(i8* %4, i8* %12, i64 %13)
%25 = load i8, i8* %4
%26 = icmp eq i8 %25, 115
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 1
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 101
%30 = select i1 %26, i1 %29, i1 false
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 2
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 114
%34 = select i1 %30, i1 %33, i1 false
br i1 %34, label %35, label %37
35: ; preds = %23
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %37
37: ; preds = %23, %35
ret i32 0
}