#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 */
struct udev {
  int dummy;
};

/* Variables and functions */
char *strchr(char *, char);
int /*<<< orphan*/ udev_log_null(struct udev *, char *, ...);
char *get_format_attribute(struct udev *udev, char **str) {
  char *pos;
  char *attr = NULL;
  if (*str[0] == '{') {
    pos = strchr(*str, '}');
    if (pos == NULL) {
      udev_log_null(udev, "missing closing brace for format\n");
      return NULL;
    }
    pos[0] = '\0';
    attr = *str + 1;
    *str = pos + 1;
    udev_log_null(udev, "attribute='%s', str='%s'\n", attr, *str);
  }
  return attr;
}


x86 assembly (clang, -O0):
<get_format_attribute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x7b,%eax
jne    11cc <get_format_attribute+0xac>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    $0x7d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118a <get_format_attribute+0x6a>
mov    -0x10(%rbp),%rdi
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1030 <udev_log_null@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d4 <get_format_attribute+0xb4>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1030 <udev_log_null@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_format_attribute>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    (%rsi),%rdi
cmpb   $0x7b,(%rdi)
jne    116c <get_format_attribute+0x4c>
mov    %rsi,%rbx
mov    $0x7d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1171 <get_format_attribute+0x51>
movb   $0x0,(%rax)
mov    (%rbx),%r15
add    $0x1,%r15
add    $0x1,%rax
mov    %rax,(%rbx)
lea    0xec8(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1030 <udev_log_null@plt>
jmp    1185 <get_format_attribute+0x65>
xor    %r15d,%r15d
jmp    1185 <get_format_attribute+0x65>
lea    0xe88(%rip),%rsi
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <udev_log_null@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.udev = type { i32 }
@.str = [34 x i8] c"missing closing brace for format\0A\00"
@.str.1 = [26 x i8] c"attribute='%s', str='%s'\0A\00"
define i8* @get_format_attribute(%struct.udev* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca %struct.udev*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store %struct.udev* %0, %struct.udev** %4
store i8** %1, i8*** %5
store i8* null, i8** %7
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 123
br i1 %13, label %14, label %37
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = load i8*, i8** %15
%17 = call i8* @strchr(i8* %16, i8 signext 125)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load %struct.udev*, %struct.udev** %4
%22 = call i32 (%struct.udev*, i8*, ...) @udev_log_null(%struct.udev* %21, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %39
23: ; preds = %14
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 0
store i8 0, i8* %25
%26 = load i8**, i8*** %5
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8* %28, i8** %7
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8**, i8*** %5
store i8* %30, i8** %31
%32 = load %struct.udev*, %struct.udev** %4
%33 = load i8*, i8** %7
%34 = load i8**, i8*** %5
%35 = load i8*, i8** %34
%36 = call i32 (%struct.udev*, i8*, ...) @udev_log_null(%struct.udev* %32, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* %35)
br label %37
37: ; preds = %23, %2
%38 = load i8*, i8** %7
store i8* %38, i8** %3
br label %39
39: ; preds = %37, %20
%40 = load i8*, i8** %3
ret i8* %40
}

LLVM IR (-O2):
%struct.udev = type { i32 }
@.str = [34 x i8] c"missing closing brace for format\0A\00"
@.str.1 = [26 x i8] c"attribute='%s', str='%s'\0A\00"
define i8* @get_format_attribute(%struct.udev* %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 123
br i1 %5, label %6, label %16
6: ; preds = %2
%7 = tail call i8* @strchr(i8* %3, i8 signext 125)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 (%struct.udev*, i8*, ...) @udev_log_null(%struct.udev* %0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %16
11: ; preds = %6
store i8 0, i8* %7
%12 = load i8*, i8** %1
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = getelementptr inbounds i8, i8* %7, i64 1
store i8* %14, i8** %1
%15 = tail call i32 (%struct.udev*, i8*, ...) @udev_log_null(%struct.udev* %0, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* %14)
br label %16
16: ; preds = %2, %11, %9
%17 = phi i8* [ null, %9 ], [ %13, %11 ], [ null, %2 ]
ret i8* %17
}