#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*/ fprintf(int /*<<< orphan*/, char *);
int sscanf(char const *, char *, int *, int *, int *, int *);
int /*<<< orphan*/ stderr;
int strlen(char const *);
int validate_geometry(const char *geometry) {
  int len;
  int w, h, x, y;
  len = strlen(geometry);
  if (len > 25) {
    fprintf(stderr, "invalid geometry string: too long\n");
    return -1;
  }
  if (sscanf(geometry, "%dx%d+%d+%d", &w, &h, &x, &y) != 4) {
    fprintf(stderr, "invalid geometry string\n");
    return -2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<validate_geometry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x19,-0x14(%rbp)
jle    1173 <validate_geometry+0x43>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <validate_geometry+0x94>
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x20(%rbp),%r8
lea    -0x24(%rbp),%r9
call   1050 <sscanf@plt>
cmp    $0x4,%eax
je     11bd <validate_geometry+0x8d>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11c4 <validate_geometry+0x94>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_geometry>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x1a,%eax
jl     115e <validate_geometry+0x2e>
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    11a2 <validate_geometry+0x72>
lea    0xebe(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %rsp,%r9
mov    %rbx,%rdi
call   1050 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x4,%ecx
je     11a2 <validate_geometry+0x72>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xfffffffe,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"invalid geometry string: too long\0A\00"
@.str.1 = [12 x i8] c"%dx%d+%d+%d\00"
@.str.2 = [25 x i8] c"invalid geometry string\0A\00"
define i32 @validate_geometry(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 25
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %24
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32* %5, i32* %6, i32* %7, i32* %8)
%19 = icmp ne i32 %18, 4
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 -2, i32* %2
br label %24
23: ; preds = %16
store i32 0, i32* %2
br label %24
24: ; preds = %23, %20, %13
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"invalid geometry string: too long\0A\00"
@.str.1 = [12 x i8] c"%dx%d+%d+%d\00"
@.str.2 = [25 x i8] c"invalid geometry string\0A\00"
define i32 @validate_geometry(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = tail call i32 @strlen(i8* %0)
%11 = icmp sgt i32 %10, 25
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %21
15: ; preds = %1
%16 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3, i32* %4, i32* %5)
%17 = icmp eq i32 %16, 4
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %15, %18, %12
%22 = phi i32 [ -1, %12 ], [ -2, %18 ], [ 0, %15 ]
ret i32 %22
}