#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 */
unsigned int atoi(char *);
int /*<<< orphan*/ printf(char *);
char *strchr(char *, char);
char *strtok(char *, char *);
int examine_addr(char *addr) {
  char *ex;
  char sec_addr[3];
  char *token;
  unsigned int tes;
  int chk_ip = 0;
  ex = strchr(addr, ' ');
  if (ex != NULL) {
    printf("alamat yang di masukkan salah, mohon jangan ada spasi\n");
    return 0;
  }
  token = strtok(addr, ".");
  while (token != NULL) {
    chk_ip++;
    tes = atoi(token);
    if (tes > 255) {
      printf("alamat ip tidak ada yang lebih dari 255\n");
      return 0;
    }
    token = strtok(NULL, ".");
  }
  if (chk_ip != 4) {
    printf("alamat tidak valid\n");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<examine_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1188 <examine_addr+0x48>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1223 <examine_addr+0xe3>
mov    -0x10(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11fa <examine_addr+0xba>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xff,-0x2c(%rbp)
jbe    11e1 <examine_addr+0xa1>
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1223 <examine_addr+0xe3>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe4b(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    119c <examine_addr+0x5c>
cmpl   $0x4,-0x30(%rbp)
je     121c <examine_addr+0xdc>
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1223 <examine_addr+0xe3>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<examine_addr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1175 <examine_addr+0x35>
lea    0xedd(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe84(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
lea    0xe77(%rip),%r14
test   %rax,%rax
je     1160 <examine_addr+0x20>
mov    $0x4,%ebp
lea    0xe79(%rip),%r15
lea    0xe5d(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rdi
call   1060 <atoi@plt>
cmp    $0xff,%eax
ja     11dc <examine_addr+0x9c>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <strtok@plt>
add    $0xffffffff,%ebp
test   %rax,%rax
jne    11b0 <examine_addr+0x70>
test   %ebp,%ebp
jne    1160 <examine_addr+0x20>
mov    $0x1,%eax
jmp    116a <examine_addr+0x2a>
mov    %r15,%r14
jmp    1160 <examine_addr+0x20>

LLVM IR (-O0):
@.str = [55 x i8] c"alamat yang di masukkan salah, mohon jangan ada spasi\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [41 x i8] c"alamat ip tidak ada yang lebih dari 255\0A\00"
@.str.3 = [20 x i8] c"alamat tidak valid\0A\00"
define i32 @examine_addr(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [3 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %8
%9 = load i8*, i8** %3
%10 = call i8* @strchr(i8* %9, i8 signext 32)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %38
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = call i8* @strtok(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %17, i8** %6
br label %18
18: ; preds = %30, %15
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
store i32 %23, i32* %8
%24 = load i8*, i8** %6
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp ugt i32 %26, 255
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %38
30: ; preds = %21
%31 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %31, i8** %6
br label %18
32: ; preds = %18
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 4
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %2
br label %38
37: ; preds = %32
store i32 1, i32* %2
br label %38
38: ; preds = %37, %35, %28, %13
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c".\00"
@str = [19 x i8] c"alamat tidak valid\00"
@str.4 = [40 x i8] c"alamat ip tidak ada yang lebih dari 255\00"
@str.5 = [54 x i8] c"alamat yang di masukkan salah, mohon jangan ada spasi\00"
define i32 @examine_addr(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 32)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %18
4: ; preds = %1
%5 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %18, label %7
7: ; preds = %4, %12
%8 = phi i32 [ %13, %12 ], [ 0, %4 ]
%9 = phi i8* [ %14, %12 ], [ %5, %4 ]
%10 = tail call i32 @atoi(i8* %9)
%11 = icmp ugt i32 %10, 255
br i1 %11, label %18, label %12
12: ; preds = %7
%13 = add nuw nsw i32 %8, 1
%14 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %7
16: ; preds = %12
%17 = icmp eq i32 %13, 4
br i1 %17, label %21, label %18
18: ; preds = %7, %16, %4, %1
%19 = phi i8* [ getelementptr inbounds ([54 x i8], [54 x i8]* @str.5, i64 0, i64 0), %1 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0), %16 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @str.4, i64 0, i64 0), %7 ]
%20 = tail call i32 @puts(i8* dereferenceable(1) %19)
br label %21
21: ; preds = %18, %16
%22 = phi i32 [ 1, %16 ], [ 0, %18 ]
ret i32 %22
}