#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int sscanf(char const *, char *, int *, int *, int *, int *);
void set_ip(const char *ip, uint8_t *buf) {
  int vals[4];
  if (sscanf(ip, "%u.%u.%u.%u", &vals[0], &vals[1], &vals[2], &vals[3]) != 4) {
    perror("Invalid IP address");
    exit(1);
  }
  buf[0] = vals[0];
  buf[1] = vals[1];
  buf[2] = vals[2];
  buf[3] = vals[3];
}


x86 assembly (clang, -O0):
<set_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    -0x20(%rbp),%rcx
add    $0x4,%rcx
lea    -0x20(%rbp),%r8
add    $0x8,%r8
lea    -0x20(%rbp),%r9
add    $0xc,%r9
lea    0xe99(%rip),%rsi
call   1030 <sscanf@plt>
cmp    $0x4,%eax
je     118b <set_ip+0x5b>
lea    0xe90(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_ip>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0xeb2(%rip),%rsi
mov    %rsp,%rdx
call   1030 <sscanf@plt>
cmp    $0x4,%eax
jne    1168 <set_ip+0x38>
movaps (%rsp),%xmm0
movups %xmm0,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe9d(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"%u.%u.%u.%u\00"
@.str.1 = [19 x i8] c"Invalid IP address\00"
define void @set_ip(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [4 x i32]
store i8* %0, i8** %3
store i32* %1, i32** %4
%6 = load i8*, i8** %3
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 1
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 2
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 3
%11 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %7, i32* %8, i32* %9, i32* %10)
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%18 = load i32, i32* %17
%19 = load i32*, i32** %4
%20 = getelementptr inbounds i32, i32* %19, i64 0
store i32 %18, i32* %20
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 1
%22 = load i32, i32* %21
%23 = load i32*, i32** %4
%24 = getelementptr inbounds i32, i32* %23, i64 1
store i32 %22, i32* %24
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 2
%26 = load i32, i32* %25
%27 = load i32*, i32** %4
%28 = getelementptr inbounds i32, i32* %27, i64 2
store i32 %26, i32* %28
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 3
%30 = load i32, i32* %29
%31 = load i32*, i32** %4
%32 = getelementptr inbounds i32, i32* %31, i64 3
store i32 %30, i32* %32
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%u.%u.%u.%u\00"
@.str.1 = [19 x i8] c"Invalid IP address\00"
define void @set_ip(i8* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca <4 x i32>
%4 = bitcast <4 x i32>* %3 to i8*
%5 = getelementptr inbounds <4 x i32>, <4 x i32>* %3, i64 0, i64 0
%6 = getelementptr inbounds <4 x i32>, <4 x i32>* %3, i64 0, i64 1
%7 = getelementptr inbounds <4 x i32>, <4 x i32>* %3, i64 0, i64 2
%8 = getelementptr inbounds <4 x i32>, <4 x i32>* %3, i64 0, i64 3
%9 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %6, i32* %7, i32* %8)
%10 = icmp eq i32 %9, 4
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load <4 x i32>, <4 x i32>* %3
%16 = bitcast i32* %1 to <4 x i32>*
store <4 x i32> %15, <4 x i32>* %16
ret void
}