#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 event_config {
  int dummy;
};
struct event_base {
  int dummy;
};
typedef enum event_method_feature {
  ____Placeholder_event_method_feature
} event_method_feature;

/* Variables and functions */
int EV_FEATURE_ET;
int EV_FEATURE_O1;
char *event_base_get_method(struct event_base *);
struct event_base *event_base_new_with_config(struct event_config *);
int /*<<< orphan*/ event_config_free(struct event_config *);
struct event_config *event_config_new();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char const *);
int main(int argc, const char *argv[]) {
  struct event_config *cfg;
  struct event_base *base;
  int i;
  enum event_method_feature flags;
  flags = EV_FEATURE_O1;
  for (i = 0; i < 2; ++i) {
    cfg = event_config_new();
    if (i == 0)
      flags |= EV_FEATURE_ET;
    base = event_base_new_with_config(cfg);
    event_config_free(cfg);
    if (base) {
      const char *base_method;
      base_method = event_base_get_method(base);
      puts(base_method);
      printf("managed to find event base i=%u", i);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x2,-0x24(%rbp)
jge    1215 <main+0xb5>
mov    $0x0,%al
call   1030 <event_config_new@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11b7 <main+0x57>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <event_base_new_with_config@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <event_config_free@plt>
cmpq   $0x0,-0x20(%rbp)
je     1202 <main+0xa2>
mov    -0x20(%rbp),%rdi
call   1080 <event_base_get_method@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x24(%rbp),%esi
lea    0xe08(%rip),%rdi
call   1050 <printf@plt>
jmp    1215 <main+0xb5>
jmp    1207 <main+0xa7>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1189 <main+0x29>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <event_config_new@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <event_base_new_with_config@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1070 <event_config_free@plt>
test   %rbx,%rbx
jne    11b1 <main+0x51>
xor    %eax,%eax
call   1030 <event_config_new@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <event_base_new_with_config@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1070 <event_config_free@plt>
test   %rbx,%rbx
je     11d0 <main+0x70>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1080 <event_base_get_method@plt>
mov    %rax,%rdi
call   1040 <puts@plt>
lea    0xe38(%rip),%rdi
mov    %r14d,%esi
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.event_config = type { i32 }
%struct.event_base = type { i32 }
@EV_FEATURE_O1 = global i32 0
@EV_FEATURE_ET = global i32 0
@.str = [32 x i8] c"managed to find event base i=%u\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.event_config*
%7 = alloca %struct.event_base*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @EV_FEATURE_O1
store i32 %11, i32* %9
store i32 0, i32* %8
br label %12
12: ; preds = %38, %2
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %41
15: ; preds = %12
%16 = call %struct.event_config* (...) @event_config_new()
store %struct.event_config* %16, %struct.event_config** %6
%17 = load i32, i32* %8
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i32, i32* @EV_FEATURE_ET
%21 = load i32, i32* %9
%22 = or i32 %21, %20
store i32 %22, i32* %9
br label %23
23: ; preds = %19, %15
%24 = load %struct.event_config*, %struct.event_config** %6
%25 = call %struct.event_base* @event_base_new_with_config(%struct.event_config* %24)
store %struct.event_base* %25, %struct.event_base** %7
%26 = load %struct.event_config*, %struct.event_config** %6
%27 = call i32 @event_config_free(%struct.event_config* %26)
%28 = load %struct.event_base*, %struct.event_base** %7
%29 = icmp ne %struct.event_base* %28, null
br i1 %29, label %30, label %37
30: ; preds = %23
%31 = load %struct.event_base*, %struct.event_base** %7
%32 = call i8* @event_base_get_method(%struct.event_base* %31)
store i8* %32, i8** %10
%33 = load i8*, i8** %10
%34 = call i32 @puts(i8* %33)
%35 = load i32, i32* %8
%36 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %35)
br label %41
37: ; preds = %23
br label %38
38: ; preds = %37
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %12
41: ; preds = %30, %12
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
%struct.event_config = type { i32 }
%struct.event_base = type { i32 }
@EV_FEATURE_O1 = global i32 0
@EV_FEATURE_ET = global i32 0
@.str = [32 x i8] c"managed to find event base i=%u\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call %struct.event_config* (...) @event_config_new()
%4 = tail call %struct.event_base* @event_base_new_with_config(%struct.event_config* %3)
%5 = tail call i32 @event_config_free(%struct.event_config* %3)
%6 = icmp eq %struct.event_base* %4, null
br i1 %6, label %13, label %7
7: ; preds = %13, %2
%8 = phi i32 [ 0, %2 ], [ 1, %13 ]
%9 = phi %struct.event_base* [ %4, %2 ], [ %15, %13 ]
%10 = tail call i8* @event_base_get_method(%struct.event_base* %9)
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %18
13: ; preds = %2
%14 = tail call %struct.event_config* (...) @event_config_new()
%15 = tail call %struct.event_base* @event_base_new_with_config(%struct.event_config* %14)
%16 = tail call i32 @event_config_free(%struct.event_config* %14)
%17 = icmp eq %struct.event_base* %15, null
br i1 %17, label %18, label %7
18: ; preds = %13, %7
ret i32 0
}