#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 dlna_Action_Request {
  int dummy;
};

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ strcmp(char const *, char *);
char *upnp_get_string(struct dlna_Action_Request *, char const *);
int upnp_get_ui4(struct dlna_Action_Request *ar, const char *key) {
  char *value;
  int val;
  if (!ar || !key)
    return 0;
  value = upnp_get_string(ar, key);
  if (!value && !strcmp(key, "ObjectID"))
    value = upnp_get_string(ar, "ContainerID");
  if (!value)
    return 0;
  val = atoi(value);
  free(value);
  return val;
}


x86 assembly (clang, -O0):
<upnp_get_ui4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1166 <upnp_get_ui4+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1172 <upnp_get_ui4+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11ed <upnp_get_ui4+0xad>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <upnp_get_string@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bb <upnp_get_ui4+0x7b>
mov    -0x18(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11bb <upnp_get_ui4+0x7b>
mov    -0x10(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1040 <upnp_get_string@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d2 <upnp_get_ui4+0x92>
movl   $0x0,-0x4(%rbp)
jmp    11ed <upnp_get_ui4+0xad>
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upnp_get_ui4>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     11a5 <upnp_get_ui4+0x65>
mov    %rsi,%rbx
test   %rsi,%rsi
je     11a5 <upnp_get_ui4+0x65>
mov    %rdi,%r14
mov    %rbx,%rsi
call   1040 <upnp_get_string@plt>
mov    %rax,%r15
test   %rax,%rax
je     117b <upnp_get_ui4+0x3b>
mov    %r15,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
jmp    11a7 <upnp_get_ui4+0x67>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    11a5 <upnp_get_ui4+0x65>
lea    0xe74(%rip),%rsi
mov    %r14,%rdi
call   1040 <upnp_get_string@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1165 <upnp_get_ui4+0x25>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dlna_Action_Request = type { i32 }
@.str = [9 x i8] c"ObjectID\00"
@.str.1 = [12 x i8] c"ContainerID\00"
define i32 @upnp_get_ui4(%struct.dlna_Action_Request* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.dlna_Action_Request*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store %struct.dlna_Action_Request* %0, %struct.dlna_Action_Request** %4
store i8* %1, i8** %5
%8 = load %struct.dlna_Action_Request*, %struct.dlna_Action_Request** %4
%9 = icmp ne %struct.dlna_Action_Request* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10, %2
store i32 0, i32* %3
br label %37
14: ; preds = %10
%15 = load %struct.dlna_Action_Request*, %struct.dlna_Action_Request** %4
%16 = load i8*, i8** %5
%17 = call i8* @upnp_get_string(%struct.dlna_Action_Request* %15, i8* %16)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %27, label %20
20: ; preds = %14
%21 = load i8*, i8** %5
%22 = call i32 @strcmp(i8* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%23 = icmp ne i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = load %struct.dlna_Action_Request*, %struct.dlna_Action_Request** %4
%26 = call i8* @upnp_get_string(%struct.dlna_Action_Request* %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i8* %26, i8** %6
br label %27
27: ; preds = %24, %20, %14
%28 = load i8*, i8** %6
%29 = icmp ne i8* %28, null
br i1 %29, label %31, label %30
30: ; preds = %27
store i32 0, i32* %3
br label %37
31: ; preds = %27
%32 = load i8*, i8** %6
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %7
%34 = load i8*, i8** %6
%35 = call i32 @free(i8* %34)
%36 = load i32, i32* %7
store i32 %36, i32* %3
br label %37
37: ; preds = %31, %30, %13
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
%struct.dlna_Action_Request = type { i32 }
@.str = [9 x i8] c"ObjectID\00"
@.str.1 = [12 x i8] c"ContainerID\00"
define i32 @upnp_get_ui4(%struct.dlna_Action_Request* %0, i8* %1) {
%3 = icmp ne %struct.dlna_Action_Request* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %19
6: ; preds = %2
%7 = tail call i8* @upnp_get_string(%struct.dlna_Action_Request* %0, i8* %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = tail call i32 @strcmp(i8* %1, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = tail call i8* @upnp_get_string(%struct.dlna_Action_Request* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %6, %12
%16 = phi i8* [ %13, %12 ], [ %7, %6 ]
%17 = tail call i32 @atoi(i8* %16)
%18 = tail call i32 @free(i8* %16)
br label %19
19: ; preds = %9, %12, %2, %15
%20 = phi i32 [ %17, %15 ], [ 0, %2 ], [ 0, %12 ], [ 0, %9 ]
ret i32 %20
}