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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ create_service(struct service **, unsigned long, char *, char *,
                          char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
struct service *service_factory(unsigned long cat_id, char *desc,
                                char *long_desc, char *uri) {
  char *desc_ptr = desc ? malloc(strlen(desc) + 1) : NULL;
  char *long_desc_ptr = long_desc ? malloc(strlen(long_desc) + 1) : NULL;
  char *uri_ptr = uri ? malloc(strlen(uri) + 1) : NULL;
  struct service *s = NULL;
  if (desc_ptr)
    strcpy(desc_ptr, desc);
  if (long_desc_ptr)
    strcpy(long_desc_ptr, long_desc);
  if (uri_ptr)
    strcpy(uri_ptr, uri);
  assert(0 == create_service(&s, cat_id, desc_ptr, long_desc_ptr, uri_ptr));
  return s;
}


x86 assembly (clang, -O0):
<service_factory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1191 <service_factory+0x41>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
jmp    119c <service_factory+0x4c>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    119c <service_factory+0x4c>
mov    -0x48(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cd <service_factory+0x7d>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
jmp    11d8 <service_factory+0x88>
xor    %eax,%eax
mov    %rax,-0x50(%rbp)
jmp    11d8 <service_factory+0x88>
mov    -0x50(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1209 <service_factory+0xb9>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x58(%rbp)
jmp    1214 <service_factory+0xc4>
xor    %eax,%eax
mov    %rax,-0x58(%rbp)
jmp    1214 <service_factory+0xc4>
mov    -0x58(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     123c <service_factory+0xec>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
cmpq   $0x0,-0x30(%rbp)
je     1254 <service_factory+0x104>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
cmpq   $0x0,-0x38(%rbp)
je     126c <service_factory+0x11c>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
lea    -0x40(%rbp),%rdi
call   1060 <create_service@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x40(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<service_factory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,0x10(%rsp)
test   %rsi,%rsi
je     11b9 <service_factory+0x69>
mov    %r13,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %r12,%r12
je     11c0 <service_factory+0x70>
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbp
test   %r15,%r15
je     11c7 <service_factory+0x77>
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%r14
jmp    11ca <service_factory+0x7a>
xor    %ebx,%ebx
test   %r12,%r12
jne    118a <service_factory+0x3a>
xor    %ebp,%ebp
test   %r15,%r15
jne    11a3 <service_factory+0x53>
xor    %r14d,%r14d
movq   $0x0,0x8(%rsp)
test   %rbx,%rbx
je     11e3 <service_factory+0x93>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
test   %rbp,%rbp
je     11f3 <service_factory+0xa3>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
test   %r14,%r14
je     1203 <service_factory+0xb3>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r14,%r8
call   1060 <create_service@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    0x8(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.service = type { i32 }
define %struct.service* @service_factory(i64 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca %struct.service*
store i64 %0, i64* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %20
15: ; preds = %4
%16 = load i8*, i8** %6
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %17, 1
%19 = call i8* @malloc(i64 %18)
br label %21
20: ; preds = %4
br label %21
21: ; preds = %20, %15
%22 = phi i8* [ %19, %15 ], [ null, %20 ]
store i8* %22, i8** %9
%23 = load i8*, i8** %7
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i8*, i8** %7
%27 = call i64 @strlen(i8* %26)
%28 = add nsw i64 %27, 1
%29 = call i8* @malloc(i64 %28)
br label %31
30: ; preds = %21
br label %31
31: ; preds = %30, %25
%32 = phi i8* [ %29, %25 ], [ null, %30 ]
store i8* %32, i8** %10
%33 = load i8*, i8** %8
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = load i8*, i8** %8
%37 = call i64 @strlen(i8* %36)
%38 = add nsw i64 %37, 1
%39 = call i8* @malloc(i64 %38)
br label %41
40: ; preds = %31
br label %41
41: ; preds = %40, %35
%42 = phi i8* [ %39, %35 ], [ null, %40 ]
store i8* %42, i8** %11
store %struct.service* null, %struct.service** %12
%43 = load i8*, i8** %9
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = load i8*, i8** %9
%47 = load i8*, i8** %6
%48 = call i32 @strcpy(i8* %46, i8* %47)
br label %49
49: ; preds = %45, %41
%50 = load i8*, i8** %10
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = load i8*, i8** %10
%54 = load i8*, i8** %7
%55 = call i32 @strcpy(i8* %53, i8* %54)
br label %56
56: ; preds = %52, %49
%57 = load i8*, i8** %11
%58 = icmp ne i8* %57, null
br i1 %58, label %59, label %63
59: ; preds = %56
%60 = load i8*, i8** %11
%61 = load i8*, i8** %8
%62 = call i32 @strcpy(i8* %60, i8* %61)
br label %63
63: ; preds = %59, %56
%64 = load i64, i64* %5
%65 = load i8*, i8** %9
%66 = load i8*, i8** %10
%67 = load i8*, i8** %11
%68 = call i64 @create_service(%struct.service** %12, i64 %64, i8* %65, i8* %66, i8* %67)
%69 = icmp eq i64 0, %68
%70 = zext i1 %69 to i32
%71 = call i32 @assert(i32 %70)
%72 = load %struct.service*, %struct.service** %12
ret %struct.service* %72
}

LLVM IR (-O2):
%struct.service = type { i32 }
define %struct.service* @service_factory(i64 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca %struct.service*
%6 = icmp eq i8* %1, null
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = tail call i64 @strlen(i8* %1)
%9 = add nsw i64 %8, 1
%10 = tail call i8* @malloc(i64 %9)
br label %11
11: ; preds = %4, %7
%12 = phi i8* [ %10, %7 ], [ null, %4 ]
%13 = icmp eq i8* %2, null
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = tail call i64 @strlen(i8* %2)
%16 = add nsw i64 %15, 1
%17 = tail call i8* @malloc(i64 %16)
br label %18
18: ; preds = %11, %14
%19 = phi i8* [ %17, %14 ], [ null, %11 ]
%20 = icmp eq i8* %3, null
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = tail call i64 @strlen(i8* %3)
%23 = add nsw i64 %22, 1
%24 = tail call i8* @malloc(i64 %23)
br label %25
25: ; preds = %18, %21
%26 = phi i8* [ %24, %21 ], [ null, %18 ]
%27 = bitcast %struct.service** %5 to i8*
store %struct.service* null, %struct.service** %5
%28 = icmp eq i8* %12, null
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = tail call i32 @strcpy(i8* %12, i8* %1)
br label %31
31: ; preds = %29, %25
%32 = icmp eq i8* %19, null
br i1 %32, label %35, label %33
33: ; preds = %31
%34 = tail call i32 @strcpy(i8* %19, i8* %2)
br label %35
35: ; preds = %33, %31
%36 = icmp eq i8* %26, null
br i1 %36, label %39, label %37
37: ; preds = %35
%38 = tail call i32 @strcpy(i8* %26, i8* %3)
br label %39
39: ; preds = %37, %35
%40 = call i64 @create_service(%struct.service** %5, i64 %0, i8* %12, i8* %19, i8* %26)
%41 = icmp eq i64 %40, 0
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load %struct.service*, %struct.service** %5
ret %struct.service* %44
}