#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*/ abort();
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int main(void) {
  int matches;
  char str[10];
  str[0] = '\0';
  matches = -9;
  matches = sscanf("x ]", "%[^] ]", str);
  printf("Matches = %d, string str = \"%s\".\n", matches, str);
  printf("str should be \"x\".\n");
  if (strcmp(str, "x"))
    abort();
  str[0] = '\0';
  matches = -9;
  matches = sscanf(" ] x", "%[] ]", str);
  printf("Matches = %d, string str = \"%s\".\n", matches, str);
  printf("str should be \" ] \".\n");
  if (strcmp(str, " ] "))
    abort();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x12(%rbp)
movl   $0xfffffff7,-0x8(%rbp)
lea    -0x12(%rbp),%rdx
lea    0xe9b(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1060 <sscanf@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    -0x12(%rbp),%rdx
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x12(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11b8 <main+0x78>
mov    $0x0,%al
call   1030 <abort@plt>
movb   $0x0,-0x12(%rbp)
movl   $0xfffffff7,-0x8(%rbp)
lea    -0x12(%rbp),%rdx
lea    0xe73(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1060 <sscanf@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    -0x12(%rbp),%rdx
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x12(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1221 <main+0xe1>
mov    $0x0,%al
call   1030 <abort@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movb   $0x0,0x6(%rsp)
lea    0xe9f(%rip),%rdi
lea    0xe9c(%rip),%rsi
lea    0x6(%rsp),%rbx
mov    %rbx,%rdx
call   1070 <sscanf@plt>
lea    0xe8f(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xead(%rip),%rdi
call   1040 <puts@plt>
lea    0xe95(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1203 <main+0xb3>
movb   $0x0,0x6(%rsp)
lea    0xe79(%rip),%rdi
lea    0xe77(%rip),%rsi
lea    0x6(%rsp),%rbx
mov    %rbx,%rdx
call   1070 <sscanf@plt>
lea    0xe3c(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe6d(%rip),%rdi
call   1040 <puts@plt>
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1203 <main+0xb3>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"x ]\00"
@.str.1 = [7 x i8] c"%[^] ]\00"
@.str.2 = [34 x i8] c"Matches = %d, string str = \22%s\22.\0A\00"
@.str.3 = [20 x i8] c"str should be \22x\22.\0A\00"
@.str.4 = [2 x i8] c"x\00"
@.str.5 = [5 x i8] c" ] x\00"
@.str.6 = [6 x i8] c"%[] ]\00"
@.str.7 = [22 x i8] c"str should be \22 ] \22.\0A\00"
@.str.8 = [4 x i8] c" ] \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i8]
store i32 0, i32* %1
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
store i8 0, i8* %4
store i32 -9, i32* %2
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = call i32 @sscanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %7, i8* %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %0
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
store i8 0, i8* %17
store i32 -9, i32* %2
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%19 = call i32 @sscanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %18)
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %20, i8* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %16
%28 = call i32 (...) @abort()
unreachable
29: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"x ]\00"
@.str.1 = [7 x i8] c"%[^] ]\00"
@.str.2 = [34 x i8] c"Matches = %d, string str = \22%s\22.\0A\00"
@.str.4 = [2 x i8] c"x\00"
@.str.5 = [5 x i8] c" ] x\00"
@.str.6 = [6 x i8] c"%[] ]\00"
@.str.8 = [4 x i8] c" ] \00"
@str = [19 x i8] c"str should be \22x\22.\00"
@str.9 = [21 x i8] c"str should be \22 ] \22.\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
store i8 0, i8* %2
%3 = call i32 @sscanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %3, i8* %2)
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%6 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = call i32 (...) @abort()
unreachable
10: ; preds = %0
store i8 0, i8* %2
%11 = call i32 @sscanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %2)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %11, i8* %2)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0))
%14 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %10
ret i32 0
}