#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  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();
  exit(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x1e(%rbp)
movl   $0xfffffff7,-0x14(%rbp)
lea    -0x1e(%rbp),%rdx
lea    0xe84(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1060 <sscanf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    -0x1e(%rbp),%rdx
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1e(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11cf <main+0x7f>
mov    $0x0,%al
call   1030 <abort@plt>
movb   $0x0,-0x1e(%rbp)
movl   $0xfffffff7,-0x14(%rbp)
lea    -0x1e(%rbp),%rdx
lea    0xe5c(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   1060 <sscanf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    -0x1e(%rbp),%rdx
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1e(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1238 <main+0xe8>
mov    $0x0,%al
call   1030 <abort@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movb   $0x0,0x6(%rsp)
lea    0xe8f(%rip),%rdi
lea    0xe8c(%rip),%rsi
lea    0x6(%rsp),%rbx
mov    %rbx,%rdx
call   1070 <sscanf@plt>
lea    0xe7f(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9d(%rip),%rdi
call   1040 <puts@plt>
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1212 <main+0xb2>
movb   $0x0,0x6(%rsp)
lea    0xe69(%rip),%rdi
lea    0xe67(%rip),%rsi
lea    0x6(%rsp),%rbx
mov    %rbx,%rdx
call   1070 <sscanf@plt>
lea    0xe2c(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe5d(%rip),%rdi
call   1040 <puts@plt>
lea    0xe3a(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1212 <main+0xb2>
xor    %edi,%edi
call   1080 <exit@plt>
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(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
store i8 0, i8* %8
store i32 -9, i32* %6
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%10 = 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* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %11, i8* %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 (...) @abort()
unreachable
20: ; preds = %2
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
store i8 0, i8* %21
store i32 -9, i32* %6
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%23 = 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* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %24, i8* %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %20
%32 = call i32 (...) @abort()
unreachable
33: ; preds = %20
%34 = call i32 @exit(i32 0)
unreachable
}

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(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
store i8 0, i8* %4
%5 = 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* %4)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %5, i8* %4)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%8 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = call i32 (...) @abort()
unreachable
12: ; preds = %2
store i8 0, i8* %4
%13 = 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* %4)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %13, i8* %4)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0))
%16 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %12
%19 = call i32 (...) @abort()
unreachable
20: ; preds = %12
%21 = call i32 @exit(i32 0)
unreachable
}